Page 1 of 1

HTTPS bad request problem

Posted: Wednesday 19 September 2018 14:39
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

Re: HTTPS bad request problem

Posted: Wednesday 19 September 2018 20:48
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

Re: HTTPS bad request problem

Posted: Thursday 20 September 2018 18:17
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.