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.

Exceptions having references to urllib3 exceptions in "message" field

See original GitHub issue

Hey,

tldr; is exceptions keeping references to urllib3 exceptions a design choice?

I ran an issue when trying to automatically serialise TimeoutError.message. It appears it contains a reference to urllib3 exceptions:

>>> try:
...     requests.get('http://google.com', timeout=0.05)
... except Exception as e:
        pass
>>> e.message
ReadTimeoutError("HTTPConnectionPool(host='www.google.pl', port=80): Read timed out. (read timeout=0.05)",)
>>> e.message.__class__
<class 'requests.packages.urllib3.exceptions.ReadTimeoutError'>

Which is inline with I see in in the source

    elif isinstance(e, ReadTimeoutError):
          raise ReadTimeout(e, request=request)

but I wasn’t expecting this.

Python docs say:

The tuple of arguments given to the exception constructor. Some built-in exceptions (like IOError) expect a certain number of arguments and assign a special meaning to the elements of this tuple, while others are usually called only with a single string giving an error message.

Given the above I was expecting either:

  1. message to be a string ( per typical use case )
  2. message to be None and errno and strerror being set: ( because Request exceptions extend IOError and IOError having a specific constructor defined )

Was the current implementation a conscious decision? If not, what would be your preference, option (1) or (2) from the above? (2) seems more correct, (1) seems simpler.

Happy to try to PR.

Thanks!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Lukasacommented, Apr 27, 2017

As far as I can tell that should not be possible. If you’re using a custom transport adapter, though, they could be doing any number of things.

0reactions
nateprewittcommented, Aug 28, 2021

Resolving as Python 2.7 being deprecated and we’re unlikely to be investing time fixing bugs that aren’t specific to Python 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceptions - urllib3 1.26.13 documentation
exception urllib3.exceptions.ClosedPoolError(pool, message)#. Bases: PoolError. Raised when a request enters a pool after the pool has been closed.
Read more >
urllib3.exceptions.NewConnectionError error handled on one ...
Maybe you could have tried from elasticsearch.exceptions import ConnectionError and replace your NewConnectionError with that.
Read more >
Stale element reference - WebDriver - MDN Web Docs
The stale element reference error is a WebDriver error that occurs ... webdriver from selenium.common import exceptions def inline(doc): ...
Read more >
requests 2.17.0 - PyPI
from requests.packages.urllib3.poolmanager import PoolManager ... When passed objects that throw exceptions from tell(), send them via chunked transfer ...
Read more >
urllib3/CHANGES.rst at main - GitHub
This change should have no effect on users as the default value of None was an invalid option and was never ... Added...
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