Skip to content

Handle bad search API URL more nicely #1

@jypeter

Description

@jypeter

I wanted to try the example search on the IPSL esgf-node. Unfortunately, I had a typo in the URL ("esgf-search" instead of "esg-search"...) and I ended up with a big traceback. Example below

It would be nice if the user could get a friendly warning message instead of the exception. Maybe the availability of the service at the specified URL should be tested as soon as SearchConnection is called?

from pyesgf.search import SearchConnection

WRONG URL below

conn = SearchConnection('http://esgf-node.ipsl.fr/esgf-search/search', distrib=True)
ctx = conn.new_context(project='CMIP5', query='humidity')
ctx.hit_count
Traceback (most recent call last):
File "", line 1, in
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/site-packages/esgf_pyclient-0.1b1-py2.7.egg/pyesgf/search/context.py", line 139, in hit_count
self.__update_counts()
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/site-packages/esgf_pyclient-0.1b1-py2.7.egg/pyesgf/search/context.py", line 171, in __update_counts
response = self.connection.send_query(query_dict, limit=0)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/site-packages/esgf_pyclient-0.1b1-py2.7.egg/pyesgf/search/connection.py", line 75, in send_query
response = urllib2.urlopen(query_url)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/urllib2.py", line 444, in error
return self._call_chain(_args)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(_args)
File "/home/share/unix_files/cdat/versions/cdat_install_uv-1.1.0_x86_64_gcc4_08/lib/python2.7/urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions