Python Plugin - Deal with cookies?

Python and python framework

Moderator: leecollings

Post Reply
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Python Plugin - Deal with cookies?

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Delta78
Posts: 9
Joined: Sunday 30 December 2018 17:23
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin - Deal with cookies?

Post 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"
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Python Plugin - Deal with cookies?

Post by sincze »

Tnx for this great tip :D
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest