From 80daa3b8cdabfadd97f4e185098c76ff49573008 Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Sun, 14 Mar 2010 20:58:05 -0500 Subject: [PATCH] Set custom User-Agent header --- src/mw/__init__.py | 2 ++ src/mw/api.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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() -- 2.30.2