Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create better error handling with nwis.get_stats #171

Open
ehinman opened this issue Dec 12, 2024 · 1 comment
Open

Create better error handling with nwis.get_stats #171

ehinman opened this issue Dec 12, 2024 · 1 comment

Comments

@ehinman
Copy link
Collaborator

ehinman commented Dec 12, 2024

Recently ran into an error when running the following code for site 02469675 (it isn't currently maintained):

import dataretrieval
test = dataretrieval.nwis.get_stats(sites='02469675')

.....
fields = re.split('[\t]', rdb.splitlines()[count]) # points to this as being the issue
fields = [field.replace(',', '') for field in fields]
dtypes = {
'site_no': str,
 'dec_long_va': float,
   (...)
'parameter_cd': str,
}

IndexError: list index out of range

This is because the link (https://waterservices.usgs.gov/nwis/stat/?sites=02469675) returns the following:

# //Output-Format: RDB
# //Response-Status: OK
# //Response-Message: No sites found matching all criteria

I think we should accommodate these potential responses.

@thodson-usgs
Copy link
Collaborator

thodson-usgs commented Dec 12, 2024

I might handle this case specifically by searching for "No sites found" within the response. But I would also catch more general errors of this type by printing the full response in the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants