Python JSON WSP: "Faulty API Request"

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
eshreth_of_athshe
Posts: 1
Joined: Wed Mar 27, 2024 9:15 pm America/New_York
Answers: 0

Python JSON WSP: "Faulty API Request"

by eshreth_of_athshe » Wed Apr 10, 2024 4:37 pm America/New_York

I'm trying to pull data from NLDAS_NOAH0125_H via JSON Web Service Protocol subset request. However, I'm getting a request fault and I've failed to narrow down why.

My main question is this: can I extract a JSON from valid requests in the subsetter or some other tool to use as a reference? I don't know what's wrong with the request I'm making, and I'd like to see other valid requests. If that's not possible, I'd appreciate any thoughts on what I'm doing wrong with my subset request.

Here's the code I have at the moment; I've tried to change the JSON to fit my use case, but like I said, the request raises a fault. I've been following the example "How to Use the Web Services API for Dataset Searching" at:
https://github.com/nasa/gesdisc-tutorials/blob/main/notebooks/How_to_Use_the_Web_Services_API_for_Dataset_Searching.ipynb
The URL for the data product is:
https://disc.gsfc.nasa.gov/datasets/NLDAS_NOAH0125_H_2.0/summary

# Define the parameters for the data subset
product = 'NLDAS_NOAH0125_H'
begTime = '2000-01-01T00:00:00.000Z'
endTime = '2000-01-02T00:00:00.000Z'
minlon = -122.0
maxlon = -116.0
minlat = 33.0
maxlat = 38.0
varName = 'SoilM_40_100cm'

# Construct JSON WSP request for API method: subset
subset_request = {
'methodname': 'subset',
'type': 'jsonwsp/request',
'version': '1.0',
'args': {
'role': 'subset',
'start': begTime,
'end': endTime,
'box': [minlon, minlat, maxlon, maxlat],
'crop': True,
'data': [{'datasetId': product,
'variable': varName
}]
}
}

I also altered the example's get_http_data() to provide more detail in the cause of a faulty request, as shown below.

def get_http_data(request):
hdrs = {'Content-Type': 'application/json', 'Accept': 'application/json'}
data = json.dumps(request)
r = http.request('POST', svcurl, body=data, headers=hdrs)
response = json.loads(r.data)

# Check for errors
if response['type'] == 'jsonwsp/fault':
self.logger.error(response['type'])
self.logger.error('API Error: faulty request. Here is the response:')
self.logger.error(json.dumps(response, indent=4))
sys.exit('API Error: faulty request, exiting...')
return response

The output of which is:

2024-04-10 13:30:39,549:get_http_data:{
"type": "jsonwsp/fault",
"version": "1.0",
"fault": {
"code": "server",
"string": "Failed to find a service configuration matching requested constraints."
}
}

Filters:

GES DISC - mgreene
User Services
User Services
Posts: 206
Joined: Wed Sep 25, 2019 9:35 am America/New_York
Answers: 2
Been thanked: 1 time

Re: Python JSON WSP: "Faulty API Request"

by GES DISC - mgreene » Tue Apr 16, 2024 11:20 am America/New_York

Hello,

Our data and subject matter experts will examine your question and formulate a reply shortly.

Note:
To subscribe to our monthly announcements mailing list, send a message with “Subscribe” in the Subject line to gsfc-gesdisc-announcements-join@lists.nasa.gov . You may also subscribe to the list on this page: https://lists.nasa.gov/mailman3/lists/gsfc-gesdisc-announcements.lists.nasa.gov/

Post Reply