Permalink
Browse files

Added user-agent string

  • Loading branch information...
1 parent 0b934ad commit f895032d3a93e2f68be1404b6c17f24594425837 @moopet committed Jun 5, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 canopy.py
View
@@ -5,10 +5,12 @@
"""
from urllib import urlencode
-from urllib2 import urlopen
+from urllib2 import build_opener
from simplejson import load
+version = '0.1'
FORRST_API_ENDPOINT = "api.forrst.com/api/v2"
+USER_AGENT = "canopy v%s" % version
class ForrstAPIError(Exception):
@@ -43,7 +45,9 @@ def call_api(self, method, data={}, authenticate=False):
url = "%s://%s/%s" % (protocol, FORRST_API_ENDPOINT, method)
if data:
url += "?%s" % urlencode(data)
- response = load(urlopen(url))
+ opener = build_opener()
+ opener.addheaders = [('User-agent', USER_AGENT)]
+ response = load(opener.open(url))
if authenticate and response.get('authed') == 'false':
raise ForrstAPIError('authentication failure')
if response.get('stat') == 'ok':

0 comments on commit f895032

Please sign in to comment.