mroberge / hydrofunctions

A suite of convenience functions for working with hydrology data in an interactive Python session.
MIT License
62 stars 27 forks source link

annual statistics creates invalid URL #118

Closed mroberge closed 2 years ago

mroberge commented 2 years ago

Description

When I added the 'statYearType' parameter to a request for annual statistics, it printed the wrong URL but still returned something.

What I Did

hf.stats('01542500', 'annual', parameterCd='00060', statYearType='water')

Retrieved annual statistics for site #01542500 from https://waterservices.usgs.gov/nwis/stat//

Although it prints the wrong URL, it still seems to return the correct data.

mroberge commented 2 years ago

The problem is that the stats function in the USGS RDB module is the only one that sends a base URL and a dict of parameters to Requests and lets that package construct the full URL. All of the other functions construct the full URL themselves.

The result is that the stats function is the only one that doesn't know the full URL until after Requests returns a response.

The basic fix is to initially print just the base URL; once the response is returned print the response.url. If the USGS returns a non-200 code, it doesn't raise an error, hf just prints the error screen the the USGS sends, and then hf returns the response. So you can still print the response.url

So, change the end of line 641 to {response.url} instead of {url}.