urllib2.HTTPError

774 views
Skip to first unread message

sonu kumar

unread,
Nov 7, 2013, 7:22:18 PM11/7/13
to web...@googlegroups.com
Hi All,

I have made one webserver on web2py. It runs perfectly sometime and sometime it throws error: <class 'urllib2.HTTPError'> HTTP Error 404: Not Found

I am not able to understand it this error. Why my application runs smoothly sometime and sometime throws this kind of error.

Here is Traceback:
Traceback (most recent call last):
File "/opt/web-apps/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/opt/web-apps/web2py/applications/CleavPredict/controllers/default.py", line 1143, in <module>
File "/opt/web-apps/web2py/gluon/globals.py", line 372, in <lambda>
self._caller = lambda f: f()
File "/opt/web-apps/web2py/applications/CleavPredict/controllers/default.py", line 983, in pdbid_res
return pdbid_result()
File "/opt/web-apps/web2py/applications/CleavPredict/controllers/default.py", line 955, in pdbid_result
responsemmpn = urllib2.urlopen(requestmmpn)
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.6/urllib2.py", line 429, in error
result = self._call_chain(*args)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 616, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/lib64/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.6/urllib2.py", line 435, in error
return self._call_chain(*args)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 404: Not Found
It also shows the code where this error is coming:
params4 = {'from':'ID', 'to':'P_ENTREZGENEID', 'format':'tab', 'query':mmpn}
data6 = urllib.urlencode(params4)
requestmmpn = urllib2.Request('http://www.uniprot.org/mapping/', data6)
responsemmpn = urllib2.urlopen(requestmmpn)
Variables are  (why my responsemmpn is undefined and requestmmpn instance empty)


urllib2.urlopen<function urlopen>
responsemmpnundefined
requestmmpn<urllib2.Request instance>
global urllib2<module 'urllib2' from '/usr/lib64/python2.6/urllib2.pyc'>

Please let me know what I am doing wrong?

Thanks

sonu kumar

unread,
Nov 7, 2013, 7:46:18 PM11/7/13
to web...@googlegroups.com
One more thing I would like to say about this is:

I am using 4 times urllib for calling same weblinks for different purposes....Will this cause problem??? If yes how to solve this issue?

params1 = {'from':'PDB_ID', 'to':'ACC', 'format':'tab', 'query':session.pdbid.strip()}
    data1 = urllib.urlencode(params1)
    request2 = urllib2.Request('http://www.uniprot.org/mapping/', data1)
    response2 = urllib2.urlopen(request2)
    uniprotid = response2.read()

params = {'from':'ID', 'to':'MEROPS_ID', 'format':'tab', 'query':uniprotid3}
    data = urllib.urlencode(params)
    request1 = urllib2.Request('http://www.uniprot.org/mapping/', data)
    response = urllib2.urlopen(request1)

params3 = {'from':'ID', 'to':'P_ENTREZGENEID', 'format':'tab', 'query':uniprotid3}
    coexdata = urllib.urlencode(params3)
    coexrequest = urllib2.Request('http://www.uniprot.org/mapping/', coexdata)
    coexresponse = urllib2.urlopen(coexrequest)

params4 = {'from':'ID', 'to':'P_ENTREZGENEID', 'format':'tab', 'query':mmpn}
    data6 = urllib.urlencode(params4)
    requestmmpn = urllib2.Request('http://www.uniprot.org/mapping/', data6)
    responsemmpn = urllib2.urlopen(requestmmpn)

Thanks

Leonel Câmara

unread,
Nov 8, 2013, 6:50:30 AM11/8/13
to web...@googlegroups.com
From what I could test the problem is that your query is wrong in one of those steps. Check exactly what you are putting there.

sonu kumar

unread,
Nov 8, 2013, 1:59:45 PM11/8/13
to web...@googlegroups.com
I checked my query it is working fine but I found error sometime when I run 

responsemmpn = urllib2.urlopen(requestmmpn)

In first go it throws below error but second time I run this same command it works fine for me. Why this is happening??

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 389, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 502, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 421, in error
    result = self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 361, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 608, in http_error_302
    return self.parent.open(new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 389, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 502, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 427, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 361, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 510, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

Leonel Câmara

unread,
Nov 8, 2013, 3:09:24 PM11/8/13
to web...@googlegroups.com
Probably the server is doing the redirect wrong.

I would use something like this

To further inspect what's going on. Check the location you get in the 302.
Reply all
Reply to author
Forward
0 new messages