question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"buffering" arg support is checked on every call to `ConnectionCls.getresponse()` in HTTPConnectionPool

See original GitHub issue

On Python 3.5 with urllib3 1.15, I just hit the issue discussed in https://github.com/kennethreitz/requests/issues/1289#issuecomment-31294851 where urllib3 is checking for buffering parameter support first, and then falling back to calling getresponse() without any arguments, creating a misleading stack trace when the latter call fails.

Thanks to https://github.com/shazow/urllib3/commit/7fa026c37a5326dcaf97cb9c66ecd15df9c1a194 more recent versions of urllib3 won’t show the confusing chained traceback when a connection fails.

However, it’s also the case that on every current Python version except Python 2.7, the first call will always fail (and even on Python 2.7 it’s relying on an undocumented parameter, so not all Python implementations will support it).

This problem could be eliminated by checking for the relevant signature information once at import time rather than on every call to getresponse:

def _request_response_buffering():
    try:
        names = HTTPConnection.getresponse.im_func.func_code.co_varnames
    except AttributeError:
        return False # Either Python 3 or not CPython
    return "buffering" in names

if _request_response_buffering():
    def _getresponse(conn):
        return conn.getresponse(buffering=True)
else:
    _getresponse = HTTPConnection.getresponse

And then calling _getreponse(conn) instead of conn.getresponse()

If such an approach would be acceptable, then I’d be happy to create a PR for it.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Lukasacommented, Nov 22, 2016

I’m open to that, but I should warn you now: there’s plans afoot to remove the use of httplib altogether, so such a patch will have a shortish useful lifetime (less than 6 months I’d hope). It’s up to you whether that makes it worthwhile to you: if it does, I’m certainly happy to review and merge it.

0reactions
sethmlarsoncommented, Jan 3, 2022

This problem is removed in v2.0 after dropping Python 2.7, going to close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

getresponse() got an unexpected keyword argument 'buffering ...
I am using Python 3.4.3 with latest requests API. The error I get is: Traceback (most recent call last): File "C:\Python34\lib ...
Read more >
version-control-tools: changeset 7295 ... - Mercurial
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,...
Read more >
changed the virtualenv (5946ce9a) · Commits
pid lockfiles don't support threaded operation, so always force. # False as the threaded arg. LockBase.__init__(self, path, False, timeout).
Read more >
https://phab.mercurial-scm.org/D1026?id=2625&downl...
So we check whether + # the TLS Library still thinks it's matching hostnames. ... Python 3 + try: + httplib_response = conn.getresponse()...
Read more >
firefox-esr - debian - Progress Linux
+* Put the connection back in the pool when calling stream() or ... + * Better unicode support for filepost using StringIO buffers....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found