10000 pool.getaddrinfo() raises OSError of -2 when attempting to resolve invalid DNS name · Issue #6941 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content
8000

pool.getaddrinfo() raises OSError of -2 when attempting to resolve invalid DNS name #6941

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

Closed
jdimpson opened this issue Sep 23, 2022 · 2 comments · Fixed by #7269
Closed
Milestone

Comments

@jdimpson
Copy link

The behavior below is correct, but the Exception type / error message could be more helpful.

Example problem code and results

Adafruit CircuitPython 7.3.2 on 2022-07-20; Adafruit QT Py ESP32S2 with ESP32S2
>>> 
>>> import wifi
>>> import socketpool
>>> from secrets import secrets
>>> wifi.radio.connect(secrets["ssid"], secrets["password"])
>>> pool = socketpool.SocketPool(wifi.radio)
>>> server="nosuchhostname"
>>> pool.getaddrinfo(host=server, port=443)[0][4][0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: -2
>>> 

Expected result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SocketPoolNameError: No such domain name

or at least some text describing what OSError of -2 means, but since DNS failure is a common error, it would be nicer to be able to do, say:

try:
  pool.getaddrinfo(host=server, port=443)[0][4][0]
except SocketPoolNameError:
  server = false  # mark unavailable

rather than special-casing the exception every time you do a DNS lookup:

try:
  pool.getaddrinfo(host=server, port=443)[0][4][0]
except OSError as e:
  if int(str(e)) == -2:
    server = false  # mark unavailable
  else:
    raise e

Thank you for your consideration and all your hard work!

@jepler jepler added this to the Long term milestone Sep 26, 2022
@DJDevon3
Copy link

Ran into something similar on my S3 feather tonight with OSError -2 pointing at response = requests.get(DATA_SOURCE).json() but more specifically line 509 in adafruit_requests.py (8.0.0-beta.0-67) for _get_socket. This happened as I lost power during hurricane ian.

No clue if this is helpful, first time i've seen an actual error instead of the hard fault handler crash so wanted to document it somewhere, this seems appropriate.

@jepler
Copy link
jepler commented Nov 28, 2022

For compatibility with 7.x, code can catch OSError and check for e.errno == -2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0