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

Handle bad search API URL more nicely #1

Open
jypeter opened this issue Jan 22, 2013 · 2 comments
Open

Handle bad search API URL more nicely #1

jypeter opened this issue Jan 22, 2013 · 2 comments

Comments

@jypeter
Copy link

jypeter commented Jan 22, 2013

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

@stephenpascoe
Copy link
Owner

I suggest a SearchConnection.verify() method or similar to test the connection and catching the HTTPError to make a shorter traceback.

@stephenpascoe
Copy link
Owner

Hi Jean-Yves,

Thanks for submitting the issue to github. It's a good suggestion -- I'll get to it when I can.

Stephen.


Stephen Pascoe +44 (0)1235 445980
Centre of Environmental Data Archival
STFC Rutherford Appleton Laboratory, Harwell Oxford, Didcot OX11 0QX, UK

From: Jean-Yves Peterschmitt [mailto:notifications@github.com]
Sent: 22 January 2013 13:32
To: stephenpascoe/esgf-pyclient
Subject: [esgf-pyclient] Handle bad search API URL more nicely (#1)

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


Reply to this email directly or view it on GitHubhttps://github.com//issues/1.

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