0

Python ConnectionError
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Python ConnectionError

by ross0201 on Thu Jan 30, 2020 6:08 pm

I'm running a program based off of the "Adafruit IO Basics: Temperature & Humidity" guide. It runs fine and reports everything it should to the IO server for a few days. Then it will stop with the error pasted below.

I'm running basically the same program on two different Raspberry Pi Zero's. Both will stop running occasionally. Restarting the program works just fine; I'd just like this to be hands off.

Error:
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='io.adafruit.com', port=443): Max retries exceeded with url: /api/v2/**username**/feeds/pipes/data (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb55f7bf0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

ross0201
 
Posts: 7
Joined: Sun Dec 08, 2019 4:59 pm

Re: Python ConnectionError

by brubell on Fri Jan 31, 2020 12:15 pm

Do you know which line(s) in the code throw this error?

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: Python ConnectionError

by ross0201 on Fri Jan 31, 2020 12:21 pm

No, that's the whole error message from Thonny.

Could it be losing WiFi or internet and the program just can't restart?

ross0201
 
Posts: 7
Joined: Sun Dec 08, 2019 4:59 pm

Re: Python ConnectionError

by brubell on Fri Jan 31, 2020 12:48 pm

ross0201 wrote:No, that's the whole error message from Thonny.

Could it be losing WiFi or internet and the program just can't restart?

It could be dropping on the router-side, IoT projects are tough to troubleshoot.

Possibly you could add logging or print()'s around your code to track where it failed?

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: Python ConnectionError

by ross0201 on Fri Jan 31, 2020 12:52 pm

I could definitely try. Is there a recourse you would suggest. I'm not a programmer, just managed to paste some stuff together.

ross0201
 
Posts: 7
Joined: Sun Dec 08, 2019 4:59 pm

Re: Python ConnectionError

by ross0201 on Wed Feb 05, 2020 12:07 pm

brubell wrote:
ross0201 wrote:No, that's the whole error message from Thonny.

Could it be losing WiFi or internet and the program just can't restart?

It could be dropping on the router-side, IoT projects are tough to troubleshoot.

Possibly you could add logging or print()'s around your code to track where it failed?


Here's a longer error message:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/Desktop/temp_well.py", line 95, in <module>
aio.send(probe_feed.key, str(probe))
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 154, in send_data
return self.create_data(feed, payload)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 254, in create_data
return Data.from_dict(self._post(path, data._asdict()))
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 126, in _post
data=json.dumps(data))
File "/usr/lib/python3/dist-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='io.adafruit.com', port=443): Max retries exceeded with url: /api/v2/*USERNAME*/feeds/outside/data (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb544fbb0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

ross0201
 
Posts: 7
Joined: Sun Dec 08, 2019 4:59 pm

Re: Python ConnectionError

by ross0201 on Wed Feb 05, 2020 2:10 pm

Here's another after only running a few hours:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 57, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 301, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0xb5569050>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='io.adafruit.com', port=443): Max retries exceeded with url: /api/v2/*USERNAME*/feeds/outside/data (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb5569050>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/Desktop/temp_well.py", line 95, in <module>
aio.send(probe_feed.key, str(probe))
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 154, in send_data
return self.create_data(feed, payload)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 254, in create_data
return Data.from_dict(self._post(path, data._asdict()))
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_IO/client.py", line 126, in _post
data=json.dumps(data))
File "/usr/lib/python3/dist-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='io.adafruit.com', port=443): Max retries exceeded with url: /api/v2/*USERNAME*/feeds/outside/data (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb5569050>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
>>>

ross0201
 
Posts: 7
Joined: Sun Dec 08, 2019 4:59 pm

Re: Python ConnectionError

by brubell on Thu Feb 06, 2020 10:14 am

That error means that a DNS problem occurred and the library was unable to resolve the Adafruit IO IP Address.

Do you have a VPN/Proxy/Firewall on your computer or network?

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: Python ConnectionError

by ross0201 on Thu Feb 06, 2020 10:33 am

I don't know, this is for a cabin so I'm not there, maybe I can log in through VNC and the raspberry pies. Would it be a firewall if it works for a while then stops?

Should I try to whitelist the address in the error message?

Thanks for your help!

ross0201
 
Posts: 7
Joined: Sun Dec 08, 2019 4:59 pm

Re: Python ConnectionError

by brubell on Thu Feb 06, 2020 10:38 am

ross0201 wrote:I don't know, this is for a cabin so I'm not there, maybe I can log in through VNC and the raspberry pies. Would it be a firewall if it works for a while then stops?

Should I try to whitelist the address in the error message?

Thanks for your help!


Whitelisting io.adafruit.com would be a good idea, I'm not sure why it's stopping. There's a chance it's attempting to resolve the URL too quickly, I've put in an issue for implementing a longer backoff period to avoid this https://github.com/adafruit/Adafruit_IO ... issues/110

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.