HTTPS bad request problem

Python and python framework

Moderator: leecollings

Post Reply
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

HTTPS bad request problem

Post by heggink »

I am trying to convert a requests based HTTPS call into the python framework but struggling to get it to work. The original call is as follows:

base_url = "https://api.life360.com/v3/"
token_url = "oauth2/token.json"

Code: Select all

    circles_url = "circles.json"
    circle_url = "circles/"
    authorization_token = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="

    headers = {'Accept': 'application/json'}
    authheader="Basic " + authorization_token
    headers.update({'Authorization': authheader, 'cache-control': "no-cache",})
    url = self.base_url + self.token_url
    params = {
        "grant_type":"password",
        "username":self.username,
        "password":self.password,
    }
     r = requests.post(url, data=params, headers=headers)
The plugin call si as follows:

Code: Select all

    self.authorization_token = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="
    params = {
        "grant_type": "password",
        'username': self.username,
        'password': self.password,
    }
    headers = { 'Content-Type': 'application/json; charset=utf-8', \
                'Accept': 'application/json', \
                'cache-control': "no-cache", \
                'Authorization': "Basic " + self.authorization_token, \
                'User-Agent':'Domoticz/1.0' }

    Connection.Send({'Verb':'POST', 'URL':self.token_url, 'Headers': headers, 'Data': params})
but results in a HTTP BAD REQUEST error (the connect itself is fine and onConnect gets called). Aything 'obvious I am missing? I never used the plugin this way so struggling to make it work :-(.

Thanks for the help!

H
ps: original code at https://github.com/harperreed/life360-python
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
brunonar
Posts: 10
Joined: Monday 23 October 2017 3:22
Target OS: Windows
Domoticz version:
Contact:

Re: HTTPS bad request problem

Post by brunonar »

Try to use curl on both versions to get the RAW data. You'll find out the difference between the two codes.
To get the raw data you can do it, for example:
https://stackoverflow.com/questions/430 ... -with-curl
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: HTTPS bad request problem

Post by heggink »

Found the culprit with help from dnpwwo: Don't use Username and Password keywords in the plugin unless you intend to use this mechanism in authentication. I needed my own authentication causing the plugin to misbehave. Switching to a Mode parameter fixed it.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest