gaierror: [Errno -2] 名称或服务未知
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()
但它抛出: in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno -2] Name or service notknown
原因是什么?这是什么错误?
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
What is the reason ? What is this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用相对于服务器的 URI 来调用 request()。如果
url
是www.google.com/images?q=test
您必须执行以下操作:You need to call request() with the URI relative to the server. If
url
iswww.google.com/images?q=test
you have to do: