gaierror: [Errno -2] 名称或服务未知 [英] gaierror: [Errno -2] Name or service not known
本文介绍了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 not known
是什么原因?这是什么错误?
What is the reason ? What is this error?
推荐答案
您需要使用相对于服务器的 URI 调用 request().如果 url
是 www.google.com/images?q=test
你必须这样做:
You need to call request() with the URI relative to the server. If url
is www.google.com/images?q=test
you have to do:
conn = httplib.HTTPSConnection('www.google.com')
conn.request('GET', '/images?q=test')
这篇关于gaierror: [Errno -2] 名称或服务未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文