def request(self, query):
"""
This function was intended as an internal method - it just takes the query
you pass it and sends it to the API along with your API ID & Key. If you
know the API or rest real well have at it.
"""
if not self.custid or not self.custkey:
raise Exception('Customer ID and Customer Key are required')
fullQuery = self.host + query #host part doesn't change
if self.debug:
print "fullQuery: " + fullQuery
headers = self.getHeaders() #format the API key & ID
#check for proxy information
proxies = urllib.getproxies()
#use requests library to pull request
r = requests.get( fullQuery, headers=headers, proxies=proxies )
#Error handling for HTTP request
# 400 - bad request
if r.status_code == 400:
raise Exception('HTTP Error 400 - Bad request.')
# 404 - oh shit
if r.status_code == 404:
raise Exception('HTTP Error 404 - awww snap.')
# catch all?
if r.status_code != 200:
raise Exception('HTTP Error: ' + str(r.status_code) )
return r
#end request()
评论列表
文章目录