Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

python - [python3]socket.gaierror: [Errno 11001] getaddrinfo failed

I know that there are many similar answers to the question, use VPN and unblock it from firewall, but tried all and nothing seems to work. So, I added the question as a last resort.

I am new to python, I tried what they say and didn't understand the theory behind the answers that I found. spec: windows 10. python 3.8.

edit : I am getting the error while binding(s.bind()).

here is the code:

import socket

class server():
hostname = socket.gethostbyname(socket.gethostname())
port = input("Enter port(8080 is default): ")

if port == '':
    port = 8080
else:
    port = int(port)
print(socket.getaddrinfo(hostname, port))

if socket.has_ipv6:
    s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
else:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind((hostname, port))
s.listen()


while True:

    (clientConnected, clientAddress) = s.accept()

    a = input("{0} is Trying to connect on port {1}
 Do want to Accept request:(Yes/y/No/n): ".format(hostname, port))

    if a == 'Yes' or a == 'y':
        print("You are connected to " + hostname)
        clientConnected.send("Succesful".encode())
        break
        # break

    if a == 'No' or a == 'n':
        print("Quitting.......")
        s.close()

    else:
        print("Invalid request .. 
 Try again")
        continue


if __name__ == "__main__" :
sever().run()

output:

C:UsersHaseebAppDataLocalProgramsPythonPython38python.exe "D:/Product Code_ 037396/Python/Tv_Remote/Server_1.py"
Enter port(8080 is default): 
Traceback (most recent call last):
File "D:/Product Code_ 037396/Python/Tv_Remote/Server_1.py", line 3, in <module>
[(<AddressFamily.AF_INET: 2>, 0, 0, '', ('127.0.0.1', 8080))]
class server():
File "D:/Product Code_ 037396/Python/Tv_Remote/Server_1.py", line 18, in server
s.bind((hostname, port))
socket.gaierror: [Errno 11001] getaddrinfo failed

Process finished with exit code 1

How should I resolve this?
thanks you.

question from:https://stackoverflow.com/questions/65868096/python3socket-gaierror-errno-11001-getaddrinfo-failed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[2] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...