3

I am building a QGIS plugin in Python to fetch Landsat images from this STAC server: https://landsatlook.usgs.gov/stac-server

I need to be able to download the thumbnails, but cannot find how to authenticate to do this programmatically. How can I authenticate to get this thumbnail jpeg using vanilla python (or standard included libs)?

Trying to fetch the url redirects to the USGS login page.

https://landsatlook.usgs.gov/data/collection02/level-2/standard/etm/2000/215/021/LE07_L2SR_215021_20000214_20211117_02_T2/LE07_L2SR_215021_20000214_20211117_02_T2_thumb_small.jpeg

NB: I do not want to use any extra python libraries that are not supplied with QGIS as it makes sharing the plugin more complex.

This is where I get redirected when attempting to download: https://ers.cr.usgs.gov/login?redirectUrl=https://ers.cr.usgs.gov/?redirect_url%3Dhttps%253A%252F%252Flandsatlook.usgs.gov%252Fdata%252Fcollection02%252Flevel-2%252Fstandard%252Foli-tirs%252F2019%252F109%252F073%252FLC08_L2SP_109073_20190527_20200828_02_T1%252FLC08_L2SP_109073_20190527_20200828_02_T1_thumb_small.jpeg

I do not want to use web scraping.

11
  • 1
    You may need to drop a netrc with credentials in the working dir or user profile dir. That's what the various USGS NASA tutorials I've seen do.
    – user2856
    Commented Sep 6, 2023 at 6:42
  • Thanks @user2856 feel free to post as an answer if you would like the points
    – staf
    Commented Sep 7, 2023 at 5:59
  • @user2856 this is actually not working in this case. I get redirected to the USGS EROS Registration Page not Earth Data as per those tutorials. I get redirected here: ers.cr.usgs.gov/login?redirectUrl=https://ers.cr.usgs.gov/…
    – staf
    Commented Sep 12, 2023 at 0:18
  • Ugh, they don't make it easy :(
    – user2856
    Commented Sep 12, 2023 at 3:49
  • I know, I cant fathom why its so hard to find documentation on this!
    – staf
    Commented Sep 12, 2023 at 4:09

1 Answer 1

0

An inelegant solution is to login to USGS using a POST request first and get the image using BeautifulSoup or another web scraping tool. I would prefer not to do this, and instead authenticate directly in the request if possible. An example that works is documented here: gdalinfo authenticate for remote file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.