[英]Error :- socket.gaierror: [Errno 11001] getaddrinfo failed in get request
import socket
mysocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysocket.connect(("http://www.py4inf.com",80))
c="http://www.py4inf.com/code/romeo.txt HTTP/1.0\r\n\r\n".encode()
mysocket.send(c)
while True:
data=mysocket.recv(512)
if len(data) <1:
break
else:
print(data.decode())
mysocket.close()
Error:-
Traceback (most recent call last):
File "D:\Python_practice_file\main.py", line 3, in <module>
mysocket.connect(("http://www.py4inf.com",80))
socket.gaierror: [Errno 11001] getaddrinfo failed
I am getting this error while I am learning web socket programming in python but it seems like I am getting an error if anyone can solve this problem I'll be very grateful.我在学习 web 套接字编程时遇到此错误,但如果有人能解决此问题,我将不胜感激。 I saw some answers but they are not related because i am not using proxy,我看到了一些答案,但它们不相关,因为我没有使用代理,
Remove the http://
part.卸下http://
零件。
This indicates protocol, which is not part of the FQDN getaddrinfo()
tries to resolve.这表明协议不是 FQDN getaddrinfo()
尝试解析的一部分。
Also change也改变
c="http://www.py4inf.com/code/romeo.txt HTTP/1.0\r\n\r\n"
to至
c="GET /code/romeo.txt HTTP/1.0\r\n\r\n"
But I suggest using urllib or requests libraries if you want to do HTTP requests.但如果你想做 HTTP 请求,我建议使用urllib或requests库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.