In python 2.5, urllib2.urlopen may lead to "HTTPError: HTTP Error 400: Bad Request" sometimes(such as google checkout xml api). This may be caused by a bug. According to this post, we may use httplib instead.
Take google checkout for example:
Take google checkout for example:
url = '/checkout/api/checkout/v2/request/Merchant/%s'%merchant_id
conn = httplib.HTTPSConnection('sandbox.google.com')
headers = {}
headers['Authorization'] = 'Basic %s' % ( base64.b64encode(merchant_id + ':' + merchant_key))
headers['Content-type'] = 'application/xml; charset=UTF-8'
headers['Accept'] =' application/xml; charset=UTF-8'
conn.request("POST", url, shopcart_xml_info, headers)
response = conn.getresponse()
return response.read()
Comments