开发者

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

开发者 https://www.devze.com 2023-02-15 20:04 出处:网络
def make_req(data, url, method=\'POST\') params = urllib.urlencode(data) 开发者_开发技巧headers = {\"Content-type\": \"application/x-www-form-urlencoded\",
  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?


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号