1

I am trying to submit a POST request to the USGS EarthExplorer inventory API. This starts with a simple log-in. They have a test page:

https://earthexplorer.usgs.gov/inventory/documentation/test

which allows you to see some formatting examples. For the log-in example, I was able to extract the URL submitted on the button press as (user and pw have been changed):

https://earthexplorer.usgs.gov/inventory/json/v/1.4.0/login?jsonRequest=%7B%22username%22%3A%22user%22%2C%22password%22%3A%22pw%22%2C%22catalogId%22%3A%22EE%22%7D

However, I cannot seem to figure out how to format this in Python using the requests library. I am open to others, but am using requests for now. I have tried creating a dictionary as:

creds = {"username": "user",
  "password": "pw",
  "authType": "",
  "catalogId": "EE"}

payload = json.dumps(creds)

When I call requests.post(url, json=payload) I am told my username parameter does not exist. I have tried other keywords like data and params as well.

I have noticed the jsonRequest parameter in the successful URL, so I tried creating a dictionary with that in there as:

creds2={"jsonRequest": [{"username": "user",
                    "password": "pw",
                    "authType": "",
                    "catalogId": "EE"}]} 

but this doesn't work either.

Any suggestions? Thanks!

1 Answer 1

1

You'll have to send a GET request and pass the creds in the query string using the params argument.

creds = {
    "username": "user",
    "password": "pw",
    "authType": "",
    "catalogId": "EE"
}
url = 'https://earthexplorer.usgs.gov/inventory/json/v/1.4.0/login'
r = requests.get(url, params={'jsonRequest':json.dumps(creds)})
print(r.json())
Sign up to request clarification or add additional context in comments.

1 Comment

awesome, thanks this worked. I tried it with the post command too and all good.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.