Skip to main content

Dear all,


I have tried to do the authentification in Python using the tutorial https://docs.sentinel-hub.com/api/latest/api/overview/authentication/#python to download third party satellite images (e.g SPOT).


from oauthlib.oauth2 import BackendApplicationClient

from requests_oauthlib import OAuth2Session


Your client credentials


client_id=“my_client_ID’”

client_secret="my_secret_id’


Create a session


client = BackendApplicationClient(client_id=client_id)

oauth = OAuth2Session(client=client)


Get token for the session


However, when I try to get the token for my session using

token = oauth.fetch_token(token_url=‘https://services.sentinel-hub.com/oauth/token’,

client_id=client_id, client_secret=client_secret)


I have the following error :

UnicodeEncodeError: ‘latin-1’ codec can’t encode characters in position 3-7: ordinal not in range(256)


It seems that it comres from the fact that my client_secret has characters like {,^,#,$ which cannot be decoded in latin-1.

You can reproduce the error using client_secret.encode(‘iso-8859-1’).decode(‘latin-1’)


How can I fix this?


Thanks a lot,

Johann

When I try to first encode my client_id using utf-8 client_secret.encode(‘utf-8’), I get the error

CustomOAuth2Error: ({‘status’: 400, ‘reason’: ‘Bad Request’, ‘message’: ‘Illegal secret!’, ‘code’: ‘OAUTH_ERROR’})


Hi Johann,


Could you give us a little more information on the version of Python that you are using and what encoding by default your version of Python is using (sys.getdefaultencoding())? It could be that your python default encoding is not utf-8 .


As you are working in Python, I would also recommend using the sentinelhub-py package that does all the Authentification steps behind the scenes for you, making it easier to get to the data. For example, here is the implementation of an object that takes care of the Sentinel Hub session: https://github.com/sentinel-hub/sentinelhub-py/blob/master/sentinelhub/sentinelhub_session.py.


Reply