简体   繁体   English

错误:- socket.gaierror:[Errno 11001] getaddrinfo 在获取请求中失败

[英]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 请求,我建议使用urllibrequests库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 socket.gaierror:[Errno 11001] getaddrinfo 失败 - socket.gaierror: [Errno 11001] getaddrinfo failed Scapy导入错误&#39;socket.gaierror:[Errno 11001] getaddrinfo失败&#39; - Scapy import error 'socket.gaierror: [Errno 11001] getaddrinfo failed' 当我在 python 中使用套接字模块时,我收到此错误:'socket.gaierror: [Errno 11001] getaddrinfo failed' - I get this error:' socket.gaierror: [Errno 11001] getaddrinfo failed' when I use the socket module in python (Python)socket.gaierror:[Errno 11001] getaddrinfo失败 - (Python) socket.gaierror: [Errno 11001] getaddrinfo failed 如何解决:socket.gaierror: [Errno 11001] getaddrinfo failed - How to solve: socket.gaierror: [Errno 11001] getaddrinfo failed socket.gaierror: [Errno 11001] getaddrinfo 在 django 中失败 - socket.gaierror: [Errno 11001] getaddrinfo failed in django 处理获取 socket.gaierror 的错误:[Errno 11001] getaddrinfo 在 Python 中使用 pyopenssl 失败 - Handling error for Getting a socket.gaierror: [Errno 11001] getaddrinfo failed using pyopenssl in Python gaierror socket.gaierror: [Errno 11001] getaddrinfo 失败 mail.send(msg) - gaierror socket.gaierror: [Errno 11001] getaddrinfo failed mail.send(msg) socket.gaierror:[Errno 11003] getaddrinfo失败 - socket.gaierror: [Errno 11003] getaddrinfo failed socket.gaierror: [Errno 11001] getaddrinfo failed" in python,同时使用简单的自定义 web 浏览器 - socket.gaierror: [Errno 11001] getaddrinfo failed" in python, while using a simple custom web browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM