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
BadStatusLine is hell to debug #51676
Comments
For whatever reason, BadStatusLine tracebacks often don't show the line Traceback (most recent call last):
File "/home/djc/src/couchdb-python/couchdb/tests/client.py", line 138,
in test_attachment_crud_with_files
doc = self.db['foo']
File "/home/djc/src/couchdb-python/couchdb/client.py", line 293, in
__getitem__
_, _, data = self.resource.get(id)
File "/home/djc/src/couchdb-python/couchdb/http.py", line 333, in get
return self._request('GET', path, headers=headers, **params)
File "/home/djc/src/couchdb-python/couchdb/http.py", line 350, in _request
credentials=self.credentials)
File "/home/djc/src/couchdb-python/couchdb/http.py", line 179, in request
resp = _try_request()
File "/home/djc/src/couchdb-python/couchdb/http.py", line 167, in
_try_request
return conn.getresponse()
File "/usr/lib/python2.6/httplib.py", line 950, in getresponse
File "/usr/lib/python2.6/httplib.py", line 390, in begin
File "/usr/lib/python2.6/httplib.py", line 354, in _read_status
BadStatusLine However, some interactive testing shows that this should work: djc@enrai couchdb-python $ python
Python 2.6.2 (r262:71600, Oct 5 2009, 12:18:48)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class CrapShoot(Exception):
... def __init__(self, a):
... self.args = a,
...
>>> raise CrapShoot('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.CrapShoot: a
>>> class ParentExc(Exception):
... pass
...
>>> class CrapShoot(ParentExc):
... def __init__(self, a):
... self.args = a,
...
>>> raise CrapShoot('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.CrapShoot: a
>>> Definition of BadStatusLine: class BadStatusLine(HTTPException):
def __init__(self, line):
self.args = line,
self.line = line
class HTTPException(Exception):
# Subclasses that define an __init__ must call Exception.__init__
# or define self.args. Otherwise, str() will fail.
pass The note here seems like a cautionary but insufficient tale... |
Also, it might be useful here if it showed repr(line) instead of just |
I think what's happening is that your connection is being closed due to |
Fixed up the repr in r48417. |
Actually r78417. |
I just got tripped up by this change, I wanted to catch the specific case of an http server closing a connection and assumed that the following would work: try: That doesn't work since e.line holds the representation of the empty string instead of just holding the empty string. I think the fragment above would be a much better way to write this test, the current alterntative of: Seems like the original fix should have been to add __repr__ to BadStatusLine rather than changing its contents. Can this be revisited? |
As far as I can tell, the “line” attribute isn’t documented anyway. But bpo-8450 is opened about improving the exception when the connection is closed. |
This change was only made in 2.7a4, not 2.6 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: