My Pico Pi W is connected to wifi - confirmed, as I can access it remotely, I see it in the router, etc...
Using this as a resource and directly copy/pasting: https://github.com/micropython/micropython/blob/v1.22-release/examples/network/http_client_ssl.py
import socket
import ssl
# I connect to WiFi here
def main(use_stream=True):
s = socket.socket()
ai = socket.getaddrinfo("google.com", 443)
print("Address infos:", ai)
addr = ai[0][-1]
print("Connect address:", addr)
s.connect(addr)
s = ssl.wrap_socket(s)
print(s)
if use_stream:
# Both CPython and MicroPython SSLSocket objects support read() and
# write() methods.
s.write(b"GET / HTTP/1.0\r\n\r\n")
print(s.read(4096))
else:
# MicroPython SSLSocket objects implement only stream interface, not
# socket interface
s.send(b"GET / HTTP/1.0\r\n\r\n")
print(s.recv(4096))
s.close()
main()
Address infos: [(2, 1, 0, '', ('142.250.179.238', 443))]
Connect address: ('142.250.179.238', 443)
Traceback (most recent call last):
File "main.py", line 64, in <module>
File "main.py", line 47, in main
OSError: (-29312, 'MBEDTLS_ERR_SSL_CONN_EOF')
# Line 47 = s = ssl.wrap_socket(s)
# Line 64 = main()
This feels like it should be something so simple
I've tried also using urequests
as in r = urequests.get("https://google.com")
which returns the same exception, with and without stream in the first example (write/read vs send/recv), and with a different server / endpoint.
When connecting to WiFi, the import had a gc.threshold(500)
which appears to have been the issue. Increased to gc.threshold(5000)
(and tested with gc.disable()
for good measure) and requests are successful.