Python Script for Ezlo FW HTTP API Curl commands

Hi @cw-kid,

What I could fabricate is a python script that will generate a curl config file so you can use curl commands. See attached.Ezlo_create_curl_config.zip (2.2 KB)

Run the script as follows:

python3 Ezlo_create_curl_config.py EzloIP EzloSerial userID pwd

This should create out put like this:

-H “Authorization: Basic MTA4ZDFmMTAtY…y1kMzNkMjRiYzQ2MmU=”
–insecure
–http1.1

If it does put those lines in a file for example ezlo_curl_auth

Then you can send commands as in the documentation.

curl -K ezlo_curl_auth https://EzloIP:17000/v1/method/hub/info/get

So, it can be made to work, but quite cumbersome to access my controller on my local network. Settings like on the Vera FW should be added to allow direct access if I choose o want so.

Cheers Rene

3 Likes

@reneboer

OK thanks I will try it today.

I get nothing.

I entered the local IP of the Ezlo Atom the serial number of the Atom and my Vera account username and password. I hit enter in the command prompt and it just returned to the prompt on the next line no output was shown.

I have an @ in my password if that maybe related? Just a guess.

Hi @cw-kid,
Perhaps, can you try quotes around the password? Else you can try to add the --debug flag and the script will print what goes on.

Cheers Rene

Still the same with quotes around the password.

Debug like this ?

python3 Ezlo_create_curl_config.py --debug EzloIP EzloSerial userID pwd

That just returns to the prompt as well with no output.

Cheers.

That is odd. What system are you trying this on? Does it have python3 installed? If you just enter python3 it should tell you.

LOL no.

I am on my Windows 10 laptop.

A post was merged into an existing topic: Ezlo Linux firmware - HTTP documentation preview

OK I’ve installed Python 3 on to my Windows 10 laptop and now the command runs but I see this output returned.

Traceback (most recent call last):
File “C:\Users\username\AppData\Local\Programs\Python\Python38\Ezlo_create_curl_config.py”, line 12, in
import requests
ModuleNotFoundError: No module named ‘requests’

pip install requests

@Rene, your script works perfectly. Thanks!

I’m still struggling on Windows.

I followed this install guide here for both Python and Pip. I also added the path to C:\Users\username\AppData\Local\Programs\Python\Python38 in to the Windows Environment Path System Variable and rebooted.

However I still get the same error even though PIP is now installed as confirmed by a command pip --version

C:\WINDOWS\system32>Ezlo_create_curl_config.py 192.168.1.240 72260304 username password
Traceback (most recent call last):
File “C:\Users\username\AppData\Local\Programs\Python\Python38\Scripts\Ezlo_create_curl_config.py”, line 12, in
import requests
ModuleNotFoundError: No module named ‘requests’

C:\WINDOWS\system32>pip --version
pip 20.2.1 from c:\users\username\appdata\local\programs\python\python38\lib\site-packages\pip (python 3.8)

C:\WINDOWS\system32>

Maybe I should make a Lua version you can run on a Vera? I have nearly all code from the EzloBridge plugin so it should be doable. It is just that python has much better (read up to date) network function support so i use that to figure out the correct requests and then try to do that in Lua so i do not get stuck because of the poor Lua network modules.

But, I am not a python expert by any means, so installing in on Windows I cannot help you with. I would advice my standard consultant: google search :slight_smile:

Cheers Rene

Just install WSL2 on Windows 10.

It’s a Linux kernel running inside Windows.

Search for Ubuntu on Windows Store. Get the Windows Terminal and you’ll have a working Linux box. Best thing to do when dealing with HA stuff.

I use Oracle VirtualBox and created a Pi like VM running openLuup and all for development. Makes it simple to restore or restart from scratch if i mess up. Many ways to skin a cat.

OK thanks guys for the suggestions. I will look in to them.

I need to buy an Raspberry Pi for testing Linux stuff and running some services on I want to migrate them.

Running this command just fixed it:

pip install requests

I am on the next step now I can see an output like:

-H “Authorization: Basic MTA4ZDFmMTAtY…y1kMzNkMjRiYzQ2MmU=”
–insecure
–http1.1

Do I just put the token string in to the file ezlo_curl_auth ?

And not these parts I assume.

-H “Authorization: Basic

–insecure
–http1.1

Now I am getting this after trying to run the example curl command:

curl -K ezlo_curl_auth https://192.168.0.243:17000/v1/method/hub/info/get

Warning: error trying read config from the ‘ezlo_curl_auth’ file
curl: (77) schannel: next InitializeSecurityContext failed: SEC_E_UNTRUSTED_ROOT (0x80090325) - The certificate chain was issued by an authority that is not trusted.

I placed that ‘ezlo_curl_auth’ file in my C:\curl folder wasn’t sure how it would find it.

No. You want to put all the lines output by @reneboer’s script into the ezlo_curl_auth file. You should have 3 lines total. curl will read the file specified by the -K argument and use the lines as if you had typed them on the command-line to curl.

OK if I put those other parts back in the file along with the token string like…

-H “Authorization: Basic MTA4ZDFmMTAtY…y1kMzNkMjRiYzQ2MmU=”
–insecure
–http1.1

Now it just says:

Warning: error trying read config from the ‘ezlo_curl_auth’ file
curl: (56) Recv failure: Connection was reset

I hate curl commands LOL, why don’t they make it work like Vera Luup Requests did.