how to get raw OSError's errno raises from httpcore? #2015
Replies: 3 comments 3 replies
|
I'm not sure. Question for anyone - When exceptions are chained in Python, using Some questions for you @x0day...
Possibly. We'd need to check if it's something that's always available at the point it's being raised. Where are the Python docs for what possible values it can have? |
https://docs.python.org/3/library/errno.html
you can check with this snippet. import aiohttp
import asyncio
import errno
async def fetch(url):
async with aiohttp.ClientSession() as session:
try:
await session.get(url)
except aiohttp.ClientConnectorError as exc:
if exc.os_error.errno == errno.ENOEXEC:
print("domain resolve failed.", exc.strerror)
elif exc.os_error.errno == errno.ECONNREFUSED:
print("connection refused.", exc.strerror)
elif exc.os_error.errno == errno.ECONNRESET:
print("connection reset.", exc.strerror)
elif exc.os_error.errno == errno.ECONNABORTED:
print("connection abort.", exc.strerror)
async def main():
# check for dns resolve error.
await fetch("https://www.google.notexists")
# check for connection refused error.
await fetch("http://localhost:55555")
...
if __name__ == '__main__':
asyncio.run(main()) |
with import httpcore
import errno
try:
response = httpcore.request("GET", "http://www.google.notexists/")
except httpcore.ConnectError as exc:
if isinstance(exc.args[0], OSError):
err = exc.args[0]
if err.errno == errno.ENOEXEC:
print("dns resolve failed.")not pythonic but works :) |
Uh oh!
There was an error while loading. Please reload this page.
errnocan help us check DNS resolve error or connection refused error, httpx make this two errors allConnectError.can we remove
str(exc)fromConnectErroror adderrnoforhttpx.NetworkError?httpx/httpx/_transports/default.py
Lines 74 to 80 in 4067003
or like
aiohttphasstrerroranderrnoboth?https://github.com/aio-libs/aiohttp/blob/5d70b8e1457b7aee1bf8788eb8ce180dd972ff72/aiohttp/client_exceptions.py#L120
All reactions