ShrimpingIt / medea

Low-overhead JSON tokeniser / lexer / parser library for Micropython and Python3
GNU Affero General Public License v3.0
10 stars 0 forks source link

IPv6 Networks break addrinfo logic #2

Open cefn opened 6 years ago

cefn commented 6 years ago

Connecting to an IPv6 network from python3 currently triggers the following error

File "/home/cefn/Documents/shrimping/git/medea/medea/https.py", line 18, in byteGeneratorFactory
    s.connect(addr)
TypeError: getsockaddrarg() takes exactly 2 arguments (4 given)

Which is to do with socket.getaddrinfo(host, 443) not returning the same structure from an IPv6 lookup that it does from IPv4, and the line...

addr = socket.getaddrinfo(host, 443)[0][-1]

...bakes in assumptions about IPv4 address records.

cefn commented 6 years ago

See http://docs.micropython.org/en/latest/wipy/library/usocket.html#socket-address-format-s for details of address format. Probably the use of -1 rather than 1 is the issue