summaryrefslogtreecommitdiff
path: root/genericrequest.py
diff options
context:
space:
mode:
Diffstat (limited to 'genericrequest.py')
-rwxr-xr-xgenericrequest.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/genericrequest.py b/genericrequest.py
new file mode 100755
index 0000000..bea5d67
--- /dev/null
+++ b/genericrequest.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+
+import urllib
+import urllib2
+import simplejson
+import sys
+urlencode = urllib.urlencode
+urlopen = urllib2.urlopen
+Request = urllib2.Request
+
+def request (url, data):
+ headers = {
+ 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
+ 'Accept': '*/*'
+ }
+ try:
+ data = urlencode(data)
+ req = Request(url, data, headers)
+ response = urlopen(req)
+ try:
+ thejson = response.read()
+ response = simplejson.loads(thejson)
+ except ValueError:
+ response = response.read()
+ return response
+ except IOError, e:
+ if hasattr(e, 'code'):
+ print '%s - ERROR %s' % (self.url, e.code)
+ return None
+ else:
+ return response
+