Need help

brian brfriedman at hotmail.com
Thu Mar 3 14:43:24 EST 2005


Got code from the 3rd party, maybe someone can see something wrong with
it:

def sendDataHTTP( url, postData ):
     # url format: http://www.blah.com/notrealurl

     # postData is either a dictionary or list of dictionaries
     # that contain the data that you want to post.

     responseList = []
     urlList = urlparse.urlparse( url )
     host = urlList[1]
     scriptPath = urlList[2]
     if not type( postData ) == list: postData = [ postData ]
     headers = { "Content-type": "application/x-www-form-urlencoded",
                 "Accept": "text/plain" }
     conn = httplib.HTTPConnection( host )

     for thisDict in postData:
         params = urllib.urlencode( thisDict )
         conn.request("POST", scriptPath, params, headers )
         response = conn.getresponse()
         responseList.append( (response.status,response.reason) )
     conn.close()
     return responseList




More information about the Python-list mailing list