HTTPS bad request problem

Python and python framework
Post Reply
User avatar
heggink
Posts: 599
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

HTTPS bad request problem

Post by heggink » Wednesday 19 September 2018 14:39

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
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

brunonar
Posts: 12
Joined: Monday 23 October 2017 3:22
Target OS: Windows
Domoticz version:
Contact:

Re: HTTPS bad request problem

Post by brunonar » Wednesday 19 September 2018 20:48

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: 599
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: HTTPS bad request problem

Post by heggink » Thursday 20 September 2018 18:17

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.
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

Post Reply

Who is online

Users browsing this forum: Dnpwwo and 6 guests