2011-03-07 15 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: [errno -2] नाम या सेवा

कारण क्या है? यह त्रुटि क्या है?

उत्तर

6

आपको सर्वर से संबंधित यूआरआई के साथ अनुरोध() को कॉल करने की आवश्यकता है। यदि urlwww.google.com/images?q=test है तो आपको करना होगा:

conn = httplib.HTTPSConnection('www.google.com') 
conn.request('GET', '/images?q=test') 
संबंधित मुद्दे