← index #10872Issue #5191
Off-topic · high · value 2.932
QUERY · ISSUE

AttributeError: 'module' object has no attribute 'sockaddr'

openby klint-kopened 2023-02-27updated 2023-02-27
bug

As not seen in the code the connection works. When the Error happens is when the webpage is to be loaded.

Version:
MicroPython v1.19.1-896-g2e4dda3c2 on 2023-02-25; Raspberry Pi Pico W with RP2040

Error:
File "/lib/socket.py", line 47, in accept
AttributeError: 'module' object has no attribute 'sockaddr'

Code:

import socket
from do_connect import * #  to do the connection
from test_ssid import * # to check if the ssid is there

if test_ssid:
    do_connect()
    
with open("index.html", "r") as page:
    html = page.read()

addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(1)

while True:
    cl, addr = s.accept()
   ...

Code from socket:

43  class socket(_socket.socket):
44  
45      def accept(self):
46          s, addr = super().accept()
**47          addr = _socket.sockaddr(addr)**
48          return (s, (_socket.inet_ntop(addr[0], addr[1]), addr[2]))

CANDIDATE · ISSUE

AttributeError: 'socket' object has no attribute 'SOL_SOCKET' (ESP8266)

closedby troublegumopened 2019-10-08updated 2019-10-08

I have error: "object has no attribute 'SOL_SOCKET'".

MicroPython v1.11-8-g48dcbbe60 on 2019-05-29; ESP module with ESP8266

My code example:
import socket
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

What did I do wrong?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied