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 LocationParseError uncaught by requests #4746

Closed
Arduous opened this issue Jul 23, 2018 · 2 comments
Closed

urllib3 LocationParseError uncaught by requests #4746

Arduous opened this issue Jul 23, 2018 · 2 comments
Labels

Comments

@Arduous
Copy link

Arduous commented Jul 23, 2018

When accessing a page that is not redirecting properly (in this case, port is "-1", urllib3 LocationParseError is returned without being caught by requests.
The URL currently (Jul 23rd 2018) badly redirecting: https://www.fossil.com/us/en/account-dashboard/registered-products.html

Expected Result

An exception raised by requests, like InvalidURL

Actual Result

Exception from urllib3 is not masked

Reproduction Steps

import requests
test = requests.get("https://www.fossil.com/us/en/account-dashboard/registered-products.html")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 644, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 222, in resolve_redirects
    **adapter_kwargs
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 410, in send
    conn = self.get_connection(request.url, proxies)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 314, in get_connection
    conn = self.poolmanager.connection_from_url(url)
  File "/usr/local/lib/python2.7/dist-packages/urllib3/poolmanager.py", line 277, in connection_from_url
    u = parse_url(url)
  File "/usr/local/lib/python2.7/dist-packages/urllib3/util/url.py", line 199, in parse_url
    raise LocationParseError(url)
urllib3.exceptions.LocationParseError: Failed to parse: www.fossil.com:-1

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  }, 
  "cryptography": {
    "version": "2.2.2"
  }, 
  "idna": {
    "version": "2.7"
  }, 
  "implementation": {
    "name": "CPython", 
    "version": "2.7.9"
  }, 
  "platform": {
    "release": "4.9.35-v7+", 
    "system": "Linux"
  }, 
  "pyOpenSSL": {
    "openssl_version": "1000114f", 
    "version": "18.0.0"
  }, 
  "requests": {
    "version": "2.19.1"
  }, 
  "system_ssl": {
    "version": "1000114f"
  }, 
  "urllib3": {
    "version": "1.23"
  }, 
  "using_pyopenssl": true
}

@nateprewitt
Copy link
Member

Thanks for bringing this to our attention @Arduous! We do appear to be leaking an exception when we're trying to pull a connection from the pool. We should try to identify what exceptions can be raised here and then add handling for at least urllib3.exceptions.HTTPError, and possibly more specific cases if appropriate.

@nateprewitt
Copy link
Member

Resolved with #4765.

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

No branches or pull requests

2 participants