Comments (6)
from nsidc-data-access-notebook.
This search should be replaced with earthaccess
. I have a candidate workflow here
I've added a class to handle Service capabilities as well. Maybe a plugin?
from nsidc-data-access-notebook.
Can you share the value of response.ok
and results
?
Possibly we need to add a check that the requests.get()
was successful before proceeding.
from nsidc-data-access-notebook.
The results is empty, is there somthing wrong with the granule_search_url = 'https://cmr.earthdata.nasa.gov/search/granules', because this link returns an error.
from nsidc-data-access-notebook.
That value for granule_search_url
looks right. When you click that link, you're getting an error because you haven't passed any search parameters. The code above is doing some extra work to pass those parameters to the server with requests.get(..., params=search_params, ...)
and that is causing the request URL to be modified to add the key-value pairs in search_params
as URL query parameters. Example:
>>> response = requests.get('https://example.com', params={'foo': 'bar'})
>>> response.request.url
'https://example.com/?foo=bar'
>>> response.ok
True
>>> response.status_code
200
>>> response.content
b'<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset="utf-8" />\n <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n <style type="text/css">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href="https://www.iana.org/domains/example">More information...</a></p>\n</div>\n</body>\n</html>\n'
Can you please provide:
response.request.url
: The actual URL the code is queryingresponse.ok
: Whether the query was successfulresponse.content
: The raw content received from the server. If the content is not JSON (as in the example above), thejson.loads
step would fail. Since that didn't happen, I think you got valid JSON, but the JSON contains anerrors
key instead of afeed
key.
I think the issue may be with the data you entered; I was able to reproduce this issue by specifying an invalid bounding box.
@asteiker I think we need a validity check before trying to access results['feed']
:
# or `if 'errors' in results:`
if 'feed' not in results:
# An error occurred, handle!
# should we check before json.loads() and print `response.content` instead of `results`?
# That way if we receive invalid JSON, we can see what the response looks like instead
# of failing with:
# json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
# Maybe this isn't a realistic case to be concerned with.
print(f'An error occurred: {results["errors"]}')
print(f'Request URL: {response.request.url}')
break # or raise? ¯\_(ツ)_/¯
With this new check, the code outputs a less cryptic message for my invalid input data:
An error occurred: ['[-180, -90, 180, 90] is not a valid URL encoded bounding_box']
Request URL: https://cmr.earthdata.nasa.gov/search/granules?short_name=ATL03&version=006&temporal=2021-01-01T00%3A00%3A00Z%2C2022-01-01T00%3A00%3A00Z&page_size=100&page_num=1&bounding_box=-180%2C+-90%2C+180%2C+90
from nsidc-data-access-notebook.
Great! Thanks for surfacing this issue :) I'm going to close this issue and open a new one for the error handling.
from nsidc-data-access-notebook.
Related Issues (9)
- KeyError:'token'
- Add some error handling before processing results from CMR in "Customize and Access NSIDC Data" notebook HOT 1
- docker: Error response from daemon HOT 1
- Tracking limits and cancelling orders HOT 2
- Connection Issues HOT 6
- capability url returns invalid request HOT 3
- Download seems to be truncated HOT 10
- NameError: name 'Boundingshape' is not defined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nsidc-data-access-notebook.