urllib3: PoolManager.request() with invalid scheme produces KeyError

>>> pm = urllib3.PoolManager
>>> pm.request('GET', 'FAKESCHEME://github.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/urllib3/request.py", line 69, in request
    **urlopen_kw)
  File "/usr/local/lib/python3.5/site-packages/urllib3/request.py", line 90, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/lib/python3.5/site-packages/urllib3/poolmanager.py", line 155, in urlopen
    conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
  File "/usr/local/lib/python3.5/site-packages/urllib3/poolmanager.py", line 128, in connection_from_host
    pool = self._new_pool(scheme, host, port)
  File "/usr/local/lib/python3.5/site-packages/urllib3/poolmanager.py", line 87, in _new_pool
    pool_cls = self.pool_classes_by_scheme[scheme]
KeyError: 'FAKESCHEME'

We should be fetching by that scheme more resiliently, and raising a more specific error message - possibly a LocationValueError?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

I’d be inclined to say that we should approach this with a YAGNI train of thought. I agree with @shazow that a custom exception makes sense, but it really only makes sense if we allow pluggable schemes. If we don’t ever do that, then I don’t think that a custom exception is warranted.