summaryrefslogtreecommitdiff
path: root/stackoverflow
blob: b00678fc8633638c4482c823695eaeaa35fd7e70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python

import urllib
import urllib2
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)
        return response
    except IOError, e:
        if hasattr(e, 'code'):
            print '%s - ERROR %s' % (self.url, e.code)
            return None
        else:
            return response