Page 1 of 1

Python Plugin - Deal with cookies?

Posted: Sunday 04 August 2019 10:49
by sincze
After creating https://github.com/sincze/Domoticz-Omni ... Web-Plugin I was inspired to see if I could build some more. :lol:

Everything I use is currently running with Pass2PHP, so it is just a plugin contributing thing to spend time on and learn something (python).

In the new cases I need to store a cookie, that should be included with the future web-requests.
My first web style plugin used the example http.py however I can't determine if this can deal with cookies as well or if I should change to things I found in the Spotify plugin and use:

Code: Select all

import urllib.request
import urllib.error
import urllib.parse
import base64
import json
import time
I scanned all the plugins https://www.domoticz.com/wiki/Plugins, but still not sure what would be the best way to continue.

Re: Python Plugin - Deal with cookies?

Posted: Sunday 04 August 2019 13:57
by Delta78
It's something "easy".
When you receive a response to a request, take a look in the header, you will see a filed called "set-cookie", just extract the cookie here.
When you make the next request add a field in the header called "cookie" and add the cookie.

You don't need special encoding (just escape classic forbidden character), it can be plain text like

Code: Select all

"cookie" : "phpbb3=4111; _ga=GA1.2.191810458;pk_id.1.93f1=4f959c5d364730"

Re: Python Plugin - Deal with cookies?

Posted: Sunday 04 August 2019 17:06
by sincze
Tnx for this great tip :D