mkb79 / freeletics-python

Python client for the non-publicly Freeletics API
GNU Affero General Public License v3.0
5 stars 0 forks source link

Can't use example #1

Closed markcs closed 2 years ago

markcs commented 2 years ago

Hi,

I was trying to run the example code after updating username and password with my freeletics email address and password. However, it does not work

mark@prodesk:~/git/freeletics-python/examples$ python3.8 get_all_performed_trainings.py
get_all_performed_trainings.py:14: RuntimeWarning: coroutine 'AsyncFreeleticsClient.login' was never awaited
  client.login(USERNAME, PASSWORD)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "get_all_performed_trainings.py", line 79, in <module>
    loop.run_until_complete(async_main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "get_all_performed_trainings.py", line 20, in async_main
    r = await client.get_user_activities_by_id(page=page)
  File "/home/mark/.local/lib/python3.8/site-packages/freeletics/_client.py", line 239, in get_user_activities_by_id
    user_id = user_id or self.user_id
  File "/home/mark/.local/lib/python3.8/site-packages/freeletics/_client.py", line 87, in user_id
    return self._session.auth.refresh_token.user_id
AttributeError: 'NoneType' object has no attribute 'user_id'

Do you have any ideas?

mkb79 commented 2 years ago

There is an issue in my example here. You have to write await client.login(…). And the logout method must be rewritten to support the async client. Please use the sync client in the meantime.

mkb79 commented 2 years ago

I have updated the package and the example. If you reinstall this package you can use the fixed example

mkb79 commented 2 years ago

@markcs Can I close your issue now?

markcs commented 2 years ago

Apologies for the delay. I'm still getting errors while using your example. This time, I get an error:

  File "/usr/lib/python3/dist-packages/jwt/api_jwt.py", line 189, in _validate_aud
    raise InvalidAudienceError('Invalid audience')
jwt.exceptions.InvalidAudienceError: Invalid audience
mkb79 commented 2 years ago

That’s strange. I've tested the example in sync and async mode right now. Inserting my Freeletics username and password and it works without any issues.

Edit: can you try to update jwt?!

mkb79 commented 2 years ago

I've switched off verify the signature, so the audience verification should be deactivated too. So in theory, this exception should not be raised. I‘m using PyJWT v2.3.0.

markcs commented 2 years ago

I've updated PyJWT and it is working now. Thank you!

mkb79 commented 2 years ago

Great to hear that and no problem at all! Than I close this issue now!