While the code seems simple enough:
try:
with urllib.request.urlopen(url, timeout=0.05) as page: # this is line 202
response = page.read().strip().decode("UTF-8")
except Exception as e:
exceptPrint(e, "urllib.request.urlopen")
why do I always get this double-exception, both times in line 202 (the with … line)?
10 09:27:54.744 DEBUG : .15116 EXCEPTION: urllib.request.urlopen (<urlopen error timed out>) in file: gdev_wifiserver.py in line: 202
10 09:27:54.745 DEVEL : .15117 Traceback (most recent call last):
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/opt/python/3.10.4/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/python/3.10.4/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/python/3.10.4/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/python/3.10.4/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/opt/python/3.10.4/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/opt/python/3.10.4/lib/python3.10/http/client.py", line 941, in connect
self.sock = self._create_connection(
File "/opt/python/3.10.4/lib/python3.10/socket.py", line 845, in create_connection
raise err
File "/opt/python/3.10.4/lib/python3.10/socket.py", line 833, in create_connection
sock.connect(sa)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ullix/geigerlog/geigerlog/gdev_wifiserver.py", line 202, in getUrlResponse
with urllib.request.urlopen(url, timeout=gglobs.WiFiServerTimeout) as page:
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 1377, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/opt/python/3.10.4/lib/python3.10/urllib/request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error timed out>