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

urllib3.exceptions.InvalidHeader exception leak #4306

Closed
piotrjurkiewicz opened this issue Sep 23, 2017 · 3 comments
Closed

urllib3.exceptions.InvalidHeader exception leak #4306

piotrjurkiewicz opened this issue Sep 23, 2017 · 3 comments
Milestone

Comments

@piotrjurkiewicz
Copy link
Contributor

piotrjurkiewicz commented Sep 23, 2017

In some cases urlib3.exceptions.InvalidHeader exception is not being replaced with requests.InvalidHeader and leaks.

Expected Result

Raise requests.exceptions.InvalidHeader(RequestException, ValueError).

Actual Result

urllib3.exceptions.InvalidHeader is raised.

Stack trace

File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 515, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 502, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 612, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 616, in urlopen
**response_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 467, in from_httplib
**response_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 155, in __init__
self.length_remaining = self._init_length(request_method)
File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 229, in _init_length
"unmatching values (%s)" % length)
    
exception.type: InvalidHeader
exception.value: Content-Length contained multiple unmatching values (0, 9929)

System Information

{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.14"
  },
  "platform": {
    "release": "4.12.0-2-amd64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.1"
  },
  "system_ssl": {
    "version": "1010006f"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": false
}
@nateprewitt
Copy link
Member

nateprewitt commented Sep 23, 2017

Thanks for opening this issue, @piotrjurkiewicz! It does seem like we should try to wrap this in the Requests exception namespace. It looks like the HTTPError funnel in adapters.py raises everything it doesn't recognize here. There are actually a few newer exceptions from urllib3 I'm not sure we're accounting for in this case.

I'm not positive what the best approach is since we'll end up with an increasingly growing exception conditional list if urllib3 continues to add more exceptions. Alternatively, we could return a more generic wrapper exception but that'll likely make debugging harder. I'm sure one of the other maintainers will have a leaning on which direction to go here.

@abriginets
Copy link

Same here. Recieving an exception in console:

urllib3.exceptions.InvalidHeader: Content-Length contained multiple unmatching values (1526, 4578)

@nateprewitt
Copy link
Member

Resolved in #5914.

@nateprewitt nateprewitt added this to the 2.27.0 milestone Sep 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants