1
#Imports modules
import socket
import time

listensocket = socket.socket() #Creates an instance of socket
Port = 8000 #Port to host server on
maxConnections = 999
IP = socket.gethostname() #IP address of local machine

listensocket.bind(('',Port))

#Starts server
listensocket.listen(maxConnections)
print("Server started at " + IP + " on port " + str(Port))

#Accepts the incoming connection
(clientsocket, address) = listensocket.accept()
print("New connection made!")

running = True

while running:
    message = clientsocket.recv(1024).decode() #Gets the incoming message
    print(message)

This sketch receives text from another computer and works great in python. When I run it in micro-python I get attribute error, object has no attribute 'gethostname'

I am trying to send text from my pc to ESP32(Cardcomputer). The python sketch I use to send the text works in both python and Micro-python without any modifications or problems.

1
  • Why do you need the IP here at all? It seems like it is only used for logging and to see the log output, you already need an active connection to the device and thus most likely know the corresponding IP yourself. Commented Dec 21, 2024 at 19:57

1 Answer 1

0

The solution was simple: I changed IP = socket.gethostname() to the actual IP address: IP = "192.166.192".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.