0

I am writing a script that downloads Sentinel 2 products (satellite imagery) using sentinelsat Python API.

A product's description is structured as JSON and contains the parameter quicklook_url.

Example:

https://apihub.copernicus.eu/apihub/odata/v1/Products('862619d6-9b82-4fe0-b2bf-4e1c78296990')/Products('Quicklook')/$value

Any Sentinel API calls require credentials. So does retrieving a product and also opening the link stored inside quicklook_url. When I call the example in my browser I get asked to enter username and password in order to get

enter image description here

with the name S2A_MSIL2A_20210625T065621_N0300_R063_T39NTJ_20210625T093748-ql.jpg.

Needless to say I am just starting with the API so I am probably missing something but

requests.post(product_description['quicklook_url'], verify=False, auth=HTTPBasicAuth(username, password)).content

yields 0KB damaged file and

requests.get(product_description['quicklook_url']).content

yields 1KB damaged file.

I have looked into requests.Session

session = requests.Session()
session.auth = (username, password)
auth = session.post('URL_FOR_LOGING_IN')
img = session.get(product_description['quicklook_url']).content

The problem is I am unable to find the URL I need to post my session authentification. I am somewhat sure that the sentinelsat API does that but my looks have not yielded any successful result.

I am currently looking into the SentinelAPI class. It has the download_quicklook() function, which I am using right now but I am still curious how to do this without the function.

Ioannis Nasios
  • 8,292
  • 4
  • 33
  • 55
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161

1 Answers1

0

I guess you don't need to sent a post request. Basic authentication works by sending a header along with each request. The following should work

session = requests.Session()
session.auth = (username, password)
img = session.get(product_description['quicklook_url']).content

Your first attempt is failed because of using POST I think.

requests.gett(product_description['quicklook_url'], verify=False, auth=HTTPBasicAuth(username, password)).content

should also work.

Shanavas M
  • 1,581
  • 1
  • 17
  • 24