From: Ian Weller Date: Mon, 15 Mar 2010 01:58:05 +0000 (-0500) Subject: Set custom User-Agent header X-Git-Url: https://projects.mako.cc/source/mw/commitdiff_plain/80daa3b8cdabfadd97f4e185098c76ff49573008 Set custom User-Agent header --- diff --git a/src/mw/__init__.py b/src/mw/__init__.py index 65d03c4..5ef42b5 100644 --- a/src/mw/__init__.py +++ b/src/mw/__init__.py @@ -15,3 +15,5 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . ### + +version = '0.1' diff --git a/src/mw/api.py b/src/mw/api.py index f5dbdec..6aec91c 100644 --- a/src/mw/api.py +++ b/src/mw/api.py @@ -19,6 +19,7 @@ import cookielib import gzip import json +import mw import mw.metadir import os from StringIO import StringIO @@ -44,7 +45,9 @@ class API(object): def call(self, data): data['format'] = 'json' - request = urllib2.Request(self.api_url, urllib.urlencode(data)) + user_agent = 'mw/%s +http://github.com/ianweller/mw' % mw.version + request = urllib2.Request(self.api_url, urllib.urlencode(data), + {'User-Agent': user_agent}) request.add_header('Accept-encoding', 'gzip') response = self.opener.open(request) self.cookiejar.save()