master.The documentation indicates that message field can be used in the HTTPError:
https://github.com/encode/httpx/blob/master/httpx/_exceptions.py#L54
try:
response = httpx.get("https://www.example.com")
response.raise_for_status()
except httpx.HTTPError as exc:
print(f"HTTP Exception for {exc.request.url} - {exc.message}")
But there is not such field:
AttributeError: 'HTTPStatusError' object has no attribute 'message'
Execute the example from the doc
Print the string without raising any exceptions
AttributeError is raised
str(exc) instead of exc.messageself.message field in HTTPErrorGood catch, yup. Of those two I think we should probably set a .message attribute on the exception instances, right here... https://github.com/encode/httpx/blob/19b863af408123783d5f9916e71688b32ba558c8/httpx/_exceptions.py#L63-L64
Changing it to...
super().__init__(message)
self.message = message
self.request = request
Though you're right, the alternative would be a documentation fix, to read eg...
print(f"HTTP Exception for {exc.request.url} - {exc}")
Since BaseException.message was deprecated in 2.6 and removed in 3, I think #1255 is the one to go with.
DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
Most helpful comment
Since
BaseException.messagewas deprecated in 2.6 and removed in 3, I think #1255 is the one to go with.