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

流过昼夜 提交于 2019-12-10 20:41:19

问题


  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?


回答1:


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


来源:https://stackoverflow.com/questions/41023680/pip-upgrade-fails-inside-virtual-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!