def _urllib2_fetch(self, uri, params, method=None):
# install error processor to handle HTTP 201 response correctly
if self.opener == None:
self.opener = urllib2.build_opener(HTTPErrorProcessor)
urllib2.install_opener(self.opener)
if method and method == 'GET':
uri = self._build_get_uri(uri, params)
req = PlivoUrlRequest(uri)
else:
req = PlivoUrlRequest(uri, urllib.urlencode(params))
if method and (method == 'DELETE' or method == 'PUT'):
req.http_method = method
authstring = base64.encodestring('%s:%s' % (self.auth_id, self.auth_token))
authstring = authstring.replace('\n', '')
req.add_header("Authorization", "Basic %s" % authstring)
response = urllib2.urlopen(req)
return response.read()
评论列表
文章目录