[webservices] null returns from fdsnws-station service [SEC=UNCLASSIFIED]
Rob Newman
rnewman at iris.washington.edu
Fri Sep 12 12:16:16 PDT 2014
Hi Matthew,
Depending on what Python request library you are using (I highly recommend requests*, much more modular than urllib2), you can get the status response code easily and test for it in a try/except.
Using requests you can do this way:
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
Good luck,
- Rob Newman, IRIS DMC
* http://docs.python-requests.org/en/latest/
On Sep 11, 2014, at 8:38 PM, Matthew.Hoyles at ga.gov.au wrote:
> Hello
>
> Thank you for the quick response with useful information. We are querying from a program, I was just using a browser to test and see what was going wrong. I will modify the code to check for status code 204 and treat it as a special case.
>
> I will explain what was happening in a bit more detail, in case anyone is interested. The program (written in Python) was doing three steps: first query the station service for the station and channel metadata as XML, second parse the metadata and extract a list of channels, third request waveform data from the dataselect service (for the intersection of a list of channels of interest and the list of available channels from the metadata). The first step was apparently succeeding (204 is a success code, so the url library was not throwing an exception, as it does for 404, for example). Then an empty string was passed to the second step, causing the XML parser to throw an exception, which was reported as an error in the log files and a failed data request, rather than a no data result. In this scenario the third step, which would have interpreted an empty channel list as 'no data', was never reached.
>
> Thanks again for the help.
>
> Matthew
More information about the webservices
mailing list