magnific0 / nokia-weight-sync

Get weight from Nokia Health and update in Garmin Connect or Smashrun
GNU General Public License v3.0
71 stars 30 forks source link

Hangs: then oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter. #7

Closed magnific0 closed 6 years ago

magnific0 commented 6 years ago

@jschram writes:

I'm sorry to report that the issue wasn't fixed. It now seems to stall until a timeout occurs. This also happens when I try to setup the nokia app again:

To set a connection with Nokia Health you must have registered an application at https://account.health.nokia.com/partner/add_oauth2 .
Please enter the client id: *******
Please enter the consumer secret: *******
Please enter the callback url known by Nokia: https://localhost
Visit: https://account.health.nokia.com/oauth2_user/authorize2?response_type=code&client_id=*******&redirect_uri=https%3A%2F%2Flocalhost&scope=user.metrics&state=*******
and select your user and click "Allow this app".
Afterwards you will be redirected to your callback url with some additional parameters.
Example: https://your_original_callback?code=[code]&state=[state]
Please enter the full callback response url: https://localhost/?code=*******state=******* 

It stalls here for about 30 seconds, then fails:


Traceback (most recent call last):
File "./nokia-weight-sync.py", line 219, in <module>
setup_nokia( options, config )
File "./nokia-weight-sync.py", line 84, in setup_nokia
creds = auth.get_credentials(callback_url)
File "/srv/users/jorick/schedules/nokia-weight-sync/nokia.py", line 84, in get_credentials
client_secret=self.consumer_secret)
File "/usr/local/lib/python3.4/dist-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token
self._client.parse_request_body_response(r.text, scope=self.scope)
File "/usr/local/lib/python3.4/dist-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 408, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "/usr/local/lib/python3.4/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 379, in parse_token_response
validate_token_parameters(params)
File "/usr/local/lib/python3.4/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 389, in validate_token_parameters
raise MissingTokenError(description="Missing access token parameter.")
magnific0 commented 6 years ago

I have this exact same issue on both my laptops at home. At work this issue doesn't occur. Neither does it on my VPS.

My conclusion for the moment: https://account.health.nokia.com is blocking my IP. Perhaps too many requests, refreshing of unexpired tokens. I don't know.

My findings summarized:

magnific0 commented 6 years ago

That said, I will continue to check on the issue. Hopefully it's just a temporary matter. Otherwise I will contact Nokia API team about it (I have been in contact with them before).

jschram commented 6 years ago

Interesting. I've tried to run it from some other IP's (office, ec2 instance and another VPS) but no luck... I'd say this rules out the blocking of my IP's, as I've now ran it through IP's I've never used before for this API.

Or, maybe we've managed to break their API 😉

jschram commented 6 years ago

Anyways, thanks for your efforts!

magnific0 commented 6 years ago

That's very odd, because on my VPS it's running smoothly now. The only thing I can think of is that I did try revoking the application a few times yesterday, so perhaps it's a combination of things. You can try revoking by clicking "Disconnection" here: https://account.health.nokia.com/partner/partner

jschram commented 6 years ago

Disconnecting didn't do the trick either, tried a few times, but no luck. Did run into this message though, so I suspect they might be updating or fixing their API right now: image

magnific0 commented 6 years ago

You're right, the service is hanging for me now as well again. But I did happen to get through just now. I'm assuming it is on their end. Let's see how this plays out.

magnific0 commented 6 years ago

I had contact with Nokia, they looked at an individual request I made. Turns out urllib3 hangs for a bit before sending the request by which time the authorization_code has expired (30 seconds after Allow this app). I found a simple solutions that speed the timeout up a bit. I was able to authorize the application more consistently now.

Be aware I made some changes to the setup flow:

jschram commented 6 years ago

Works, tnx! Also see #5

magnific0 commented 6 years ago

Nice! I'm closing this issue then. Thanks.

tolrahC commented 5 years ago

Hi, I still have this issue and none of the above worked for me. Also, now Nokia doesn't allow ip address or localhost as callback url and it must be on port 80 or 443.

Here is the error

Traceback (most recent call last): File "D:\Tools\nokia-weight-sync\nokia-weight-sync.py", line 262, in <module> setup_nokia( options, config ) File "D:\Tools\nokia-weight-sync\nokia-weight-sync.py", line 128, in setup_nokia creds = auth.get_credentials(nokia_auth_code) File "D:\Tools\nokia-weight-sync\nokia.py", line 87, in get_credentials client_secret=self.consumer_secret) File "C:\Users\tolra\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests_oauthlib\oauth2_session.py", line 307, in fetch_token self._client.parse_request_body_response(r.text, scope=self.scope) File "C:\Users\tolra\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 415, in parse_request_body_response self.token = parse_token_response(body, scope=scope) File "C:\Users\tolra\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 425, in parse_token_response validate_token_parameters(params) File "C:\Users\tolra\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 435, in validate_token_parameters raise MissingTokenError(description="Missing access token parameter.") oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

magnific0 commented 5 years ago

@tolrahC I haven't tried changing my apps url in a while, but you are right that it has become more strict. Can you open a separate issue for this?

tolrahC commented 5 years ago

Just did #12