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
是什么原因?这个错误是什么?
答案 0 :(得分:7)
您需要使用相对于服务器的URI调用request()。如果url
为www.google.com/images?q=test
则必须执行:
conn = httplib.HTTPSConnection('www.google.com')
conn.request('GET', '/images?q=test')