Last active
December 7, 2023 10:09
-
-
Save willrayeo/8aa424384f272d3003a2dea6460cb07b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import credentials | |
# from creds import * | |
def get_access_token(username: str, password: str) -> str: | |
data = { | |
"client_id": "cdse-public", | |
"username": username, | |
"password": password, | |
"grant_type": "password", | |
} | |
try: | |
r = requests.post( | |
"https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token", | |
data=data, | |
) | |
r.raise_for_status() | |
except Exception as e: | |
raise Exception( | |
f"Access token creation failed. Reponse from the server was: {r.json()}" | |
) | |
return r.json()["access_token"] | |
access_token = get_access_token("USERNAME", "PASSWORD") | |
access_token = get_access_token( | |
getpass.getpass("Enter your username"), | |
getpass.getpass("Enter your password"), | |
) |
The most secure way to parse your credentials would be to use the getpass
library. However, you can also store them in a .py
file named as you wish.
This code is incomplete! The imports are missing, documentation is missing and the purpose is not clear.
@ibaris
This is a snippet, not a complete code. You can use the repository below (directory sentinel_download_new_api
) for downloading SENTINEL2 in the SAFE format, for a group of lat/lon points:
https://github.com/anikfal/GIS_solutions/tree/master
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does it mean that the credentials should be stored in a
creds.py
file?