简体   繁体   English

gaierror:[Errno -2]姓名或服务未知

[英]gaierror: [Errno -2] Name or service not known

  def make_req(data, url, method='POST')  
    params = urllib.urlencode(data)
    headers = {"Content-type": "application/x-www-form-urlencoded",
               "Accept": "text/plain",
               }
    conn = httplib.HTTPSConnection(url)
    conn.request(method, url, params, headers)
    response = conn.getresponse()
    response_data = response.read()
    conn.close()

But it is throwing: in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno -2] Name or service not known 但它抛出: in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno -2] Name or service not known

What is the reason ? 是什么原因 ? What is this error? 这个错误是什么?

You need to call request() with the URI relative to the server. 您需要使用相对于服务器的URI调用request()。 If url is www.google.com/images?q=test you have to do: 如果urlwww.google.com/images?q=test ,则必须执行以下操作:

conn = httplib.HTTPSConnection('www.google.com')
conn.request('GET', '/images?q=test')

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

相关问题 socket.gaierror:[Errno -2]服务名称未知 - socket.gaierror: [Errno -2] Name of service not known python mrjob-gaierror:[Errno -2]名称或服务未知 - python mrjob - gaierror: [Errno -2] Name or service not known socket.gaierror:[Errno -2]名称或服务未知 - socket.gaierror: [Errno -2] Name or service not known socket.gaierror gaierror:[Errno -2]名称或服务未知-pika rabbitMQ - socket.gaierror gaierror: [Errno -2] Name or service not known - pika rabbitMQ socket.gaierror:[Errno -2] Python3不知道的名称或服务 - socket.gaierror: [Errno -2] Name or service not known with Python3 Django 注册“在 /accounts/register/ [Errno -2] 名称或服务未知的 gaierror” - Django-registration "gaierror at /accounts/register/ [Errno -2] Name or service not known" jupyter throw错误:socket.gaierror:[Errno -2]名称或服务未知 - jupyter throwing error: socket.gaierror: [Errno -2] Name or service not known 使用 Kubernetes 部署的 Flask:socket.gaierror: [Errno -2] 名称或服务未知 - Flask deployed with Kubernetes: socket.gaierror: [Errno -2] Name or service not known socket.gaierror:[Errno -2]名称或服务未知| 蟒蛇 - socket.gaierror: [Errno -2] Name or service not known | Python boto3错误:socket.gaierror:[Errno -2]名称或服务未知 - boto3 Error: socket.gaierror: [Errno -2] Name or service not known
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM