Skip to content

Example needs to be updated for changes in API #7

@tommy-gilligan

Description

@tommy-gilligan

JSON decoding fails because a redirection takes the client to an inappropriate endpoint

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): account.withings.com:443
send: b'POST /oauth2/token HTTP/1.1\r\nHost: account.withings.com\r\nUser-Agent: python-requests/2.23.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 284\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
send: b'grant_type=authorization_code&client_id=REDACTED&client_secret=REDACTED&code=REDACTED&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fget_token'
reply: 'HTTP/1.1 302 Found\r\n'
header: date: Wed, 07 Feb 2024 03:50:35 GMT
header: server: Apache
header: location: https://developer.withings.com/
header: content-length: 215
header: content-type: text/html; charset=iso-8859-1
DEBUG:urllib3.connectionpool:https://account.withings.com:443 "POST /oauth2/token HTTP/1.1" 302 215
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): developer.withings.com:443
send: b'GET / HTTP/1.1\r\nHost: developer.withings.com\r\nUser-Agent: python-requests/2.23.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: date: Wed, 07 Feb 2024 03:50:36 GMT
header: server: Apache
header: last-modified: Wed, 13 Dec 2023 13:51:35 GMT
header: etag: "4502-60c64771e47c0-gzip"
header: accept-ranges: bytes
header: vary: Accept-Encoding
header: content-encoding: gzip
header: strict-transport-security: max-age=31536000, includeSubDomains
header: content-length: 4494
header: content-type: text/html
DEBUG:urllib3.connectionpool:https://developer.withings.com:443 "GET / HTTP/1.1" 200 4494
INFO:werkzeug:127.0.0.1 - - [07/Feb/2024 14:50:36] "GET /get_token?code=23b607085f7a1fc141f64e43cb17500ab8f7a78e&state=blat HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
StopIteration: 0

Changing the URL at

r_token = requests.post(f'{ACCOUNT_URL}/oauth2/token',
to https://wbsapi.withings.net/v2/oauth2. Seems to help but then the final API call fails

{
  "error": "Invalid Params: Missing params", 
  "status": 503
}

This is because the form of the JSON in the API has changed since this example was written.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions