diff options
author | neodarz <neodarz@neodarz.net> | 2020-04-19 11:42:35 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2020-04-19 11:42:35 +0200 |
commit | 84551004407a8c2c3c4a74f30c55b9fc799dc5ae (patch) | |
tree | 498983b5bc81c64515516090a54a7de15b6a8148 /README.md | |
parent | 2c8fa5251fa49bd8f7e537fbdbc801bc7bc04e59 (diff) | |
download | pyfunkwhale-84551004407a8c2c3c4a74f30c55b9fc799dc5ae.tar.xz pyfunkwhale-84551004407a8c2c3c4a74f30c55b9fc799dc5ae.zip |
Move the invalidity token management system outsite of the module
Diffstat (limited to '')
-rw-r--r-- | README.md | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -54,16 +54,30 @@ token_endpoint = "https://demo.funkwhale.audio/api/v1/oauth/token/" # Save the OAuth2 infos in file, this is ugly yup token_filename = 'oauth_token.data' +# You need to handle the invalidity of a token and ask for a new one +def _ask_new_auth(funkwhale, message): + print(message) + authorization_code = input("Enter response code: ") + funkwhale.client._set_token(authorization_code) + funkwhale = Funkwhale(client_name, redirect_uri, client_id, client_secret, scopes, username, password, domain, authorization_endpoint, token_endpoint, token_filename) -artists = funkwhale.artists() +try: + artists = funkwhale.artists() +except InvalidTokenError as e + _ask_new_auth(funkwhale, e.message) + artists = funkwhale.artists() print(artists) # In case you ask, their is an example for downloading a song -r = funkwhale.listen("f9d02c64-bafa-43cb-8e1e-fa612e7c5dab") +try: + r = funkwhale.listen("f9d02c64-bafa-43cb-8e1e-fa612e7c5dab") +except InvalidTokenError as e: + _ask_new_auth(funkwhale, e.message) + r = funkwhale.rate_limit() with open('/tmp/test.mp3', 'wb') as f: for chunk in r.iter_content(chunk_size=8192): |