Skip to content

urllib3.exceptions.InvalidHeader exception leak #4306

@piotrjurkiewicz

Description

@piotrjurkiewicz

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions