Skip to content

Missing error handling for httplib.HTTPException #24

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

Closed
yuuki0xff opened this issue Dec 5, 2018 · 3 comments
Closed

Missing error handling for httplib.HTTPException #24

yuuki0xff opened this issue Dec 5, 2018 · 3 comments
Assignees

Comments

@yuuki0xff
Copy link
Contributor

yuuki0xff commented Dec 5, 2018

The urllib2.urlopen() function may be throw the httplib.HTTPException (on python2.7) [1][2]. So i think that simplenote.py should handle the httplib.HTTPException.

[1] Full stack trace (Click to expand)
> /opt/nvpy/lib/python2.7/httplib.py(402)_read_status()
-> raise BadStatusLine("No status line received - the server has closed the connection")
(Pdb) bt
  /home/yuuki/repo/github.com/cpbotha/nvpy/nvpy/debug.py(14)wrapper()
-> return fn(*args, **kwargs)
  /home/yuuki/repo/github.com/cpbotha/nvpy/nvpy/notes_db.py(972)worker_sync()
-> result = self.update_note_to_server(o.note)
  /home/yuuki/repo/github.com/cpbotha/nvpy/nvpy/notes_db.py(1012)update_note_to_server()
-> o, err = self.simplenote.update_note(note)
  /home/yuuki/.local/lib/python2.7/site-packages/simplenote/simplenote.py(183)update_note()
-> response = urllib2.urlopen(request)
  /opt/nvpy/lib/python2.7/urllib2.py(154)urlopen()
-> return opener.open(url, data, timeout)
  /opt/nvpy/lib/python2.7/urllib2.py(429)open()
-> response = self._open(req, data)
  /opt/nvpy/lib/python2.7/urllib2.py(447)_open()
-> '_open', req)
  /opt/nvpy/lib/python2.7/urllib2.py(407)_call_chain()
-> result = func(*args)
  /opt/nvpy/lib/python2.7/urllib2.py(1241)https_open()
-> context=self._context)
  /opt/nvpy/lib/python2.7/urllib2.py(1201)do_open()
-> r = h.getresponse(buffering=True)
  /opt/nvpy/lib/python2.7/httplib.py(1121)getresponse()
-> response.begin()
  /opt/nvpy/lib/python2.7/httplib.py(438)begin()
-> version, status, reason = self._read_status()
> /opt/nvpy/lib/python2.7/httplib.py(402)_read_status()
-> raise BadStatusLine("No status line received - the server has closed the connection")
[2] Class hierarchy of the httplib.BadStatusLine (Click to expand)
$ python2
Python 2.7.15+ (default, Nov 28 2018, 16:27:22)
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>> import inspect
>>> httplib.BadStatusLine
<class 'httplib.BadStatusLine'>
>>> inspect.getmro(httplib.BadStatusLine)
(<class 'httplib.BadStatusLine'>, <class 'httplib.HTTPException'>, <type 'exceptions.Exception'>, <type 'exceptions.BaseException'>, <type 'object'>)
@atomicules
Copy link
Collaborator

Thanks for the report. Shall try to take a look soon.

@atomicules
Copy link
Collaborator

-> o, err = self.simplenote.update_note(note)
/home/yuuki/.local/lib/python2.7/site-packages/simplenote/simplenote.py(183)update_note()

That line was meant to be handled by IOError, but that doesn't seem to be working in this situation. Might just need to add in another exception or handle the existing one differently.

@atomicules atomicules self-assigned this Jan 9, 2019
@atomicules
Copy link
Collaborator

Forgot about this...

started looking again. Can do a basic webserver like so (I'm on bsd):

while true; do echo -e "HTTP/1.1 1000 OK\n\n $(date)" | nc -l localhost 1500; done

And test with:

import httplib

try:
    urllib2.urlopen('http://localhost:1500')
except httplib.BadStatusLine:
    pass

So I can look to add that in, but seems like this is an actual bug/issue in urllib2. I.e. I would have thought HTTPError should catch it (or URLError as mentioned in the linked issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants