Gaierror: [Errno -2] Name or service unknown

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 throws: 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 mistake?

+7
source share
1 answer

You need to call request () with a URI relative to the server. If url is www.google.com/images?q=test , you need to do:

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

All Articles