2011-03-07 47 views
7
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 knowngaierror:[錯誤-2]產品名稱或服務不知道

的原因是什麼?這個錯誤是什麼?

回答

6

您需要使用相對於服務器的URI調用request()。如果urlwww.google.com/images?q=test你必須這樣做:

conn = httplib.HTTPSConnection('www.google.com') 
conn.request('GET', '/images?q=test') 
相關問題