pythonpostpython-requestsraspberry-pi3home-automation

How do configure a Python post Requests command that includes a script


I have the following data:

POST /xled/v1/login HTTP/1.1
Host: 192.168.4.1
Content-Type: application/json
Content-Length: 61
{"challenge": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8="}

How do I take this data and turn it into a requests command using Python? There are lots of examples of how to create a post command using the Python Requests module, none of them seem to include the script part that is in line one of the data above (at least I have not been able to find any examples I am looking for on Google, maybe my google-fu is just weak).

I am using a Raspberry Pi 3 Model B Rev 1.2 running Raspbian GNU/Linux 10 (buster) and Python 3.7.3.

I am trying to login in to a string of "Smart" Christmas lights from Twinkly. I got the above data from the following site: https://xled-docs.readthedocs.io/en/latest/rest_api.html#api-calls

I have spent all day searching docs and causing errors in Python with my malformed commands.


Solution

  • I figured it out. There are 2 xled's that you could be dealing with if you are working on Twinkly lights. There is the python module, and then there is xled section of the web server on the lights themselves.

    So when you see /xled/v1/* What that means is r = requests.post('http://x.x.x.x/xled/v1/* ) is what the POST command should look like.

    For those completely unfamiliar with computer jargon, the x.x.x.x is the IP address of the light string in question. You can get this information from the iPhone app. And then * is whatever command you are trying to run from the documentation that I posted in my original question. Hopefully this helps clear this up for someone else as well.

    Happy Holidays!