I'm currently dealing with the implementation of a Anel Power Outlet manager. The Anel power outlet supports the following requests: https://forum.anel.eu/viewtopic.php?f=52&t=888&sid=39081b8e472aaae7ffcec4cd3fb41e83
However, the special form of the http request specifying the concatenated userpassword comma separated in the URL makes me headache, because it appears to be unsupported by the python requests package.
Therefore here my question:
How do I sent a http request in either one of the forms
http://IP?param=value,userpasswordhttp://IP?param=value&userpasswordorhttp://IP?param&userpassword
e.g.
http://192.168.0.244?Stat&userpasswordhttp://192.168.0.244?Sw=0xc0&userpassword
using the python requests package? I can sent the request manually using the browser and get the appropriate response. However, I cannot send it programmatically.
I'm struggling with the syntax as the requests documentation tells nothing about unnamed parameters (https://requests.readthedocs.io/en/latest/user/quickstart/#make-a-request).
It tells me about passing parameters as key-value pairs using a dict or a tuple or about passing parameters in the body of the request or dealing with response objects. But all this is not my problem. It's just about sending the "userpassword" string, which can either be passed as concatenated cleartext or the same base64 encoded separated by a comma or ampersand after the named parameter.
req = requests.get("IP", {"Param": "Value"}, "userpassword")
Traceback (most recent call last):
File "/home/user/pycharm-231.7864.77/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
File "<input>", line 1, in <module>
TypeError: get() takes from 1 to 2 positional arguments but 3 were given
req = requests.post("http://IP", {"Param": "Value"}, "userpassword")
req
<Response [401]>
req = requests.post("http://IP", {"Param": "Value", None: "userpassword"})
req
<Response [401]>
However, assembling the URL manually works.
req = requests.get("http://IP?Param=Value,userpassword", allow_redirects=False)
req.content
b'304 Redirect: /u_res.htm\r\n'
req2 = requests.get("http://IP/u_res.htm")
req2.text
"blablablabla"
Unfortunately, if I use an abstraction layer I would not like my code to depend on the exact details of the request format.
requests.post("http://IP", {"Param": "Value,userpassword"}It will be considered as a coma separated valueauth=parameter is not supported by the device I'm dealing with.req.url, you'll see what URL was requested.