Skip to content

Commit 670878b

Browse files
authored
Merge pull request #13 from hbrunn/master-urllib2
[IMP] use urllib2 for transparent proxy support
2 parents c91b777 + beac1b3 commit 670878b

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

pyPostcode/__init__.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'''
99

1010

11-
import httplib
11+
import urllib2
1212
import json
1313
import logging
1414

@@ -33,9 +33,9 @@ def __init__(self, api_key, api_version=(2, 0, 0)):
3333
self.api_key = api_key
3434
self.api_version = api_version
3535
if api_version >= (2, 0, 0):
36-
self.url = 'postcode-api.apiwise.nl'
36+
self.url = 'https://postcode-api.apiwise.nl'
3737
else:
38-
self.url = 'api.postcodeapi.nu'
38+
self.url = 'http://api.postcodeapi.nu'
3939

4040
def handleresponseerror(self, status):
4141
if status == 401:
@@ -61,21 +61,14 @@ def request(self, path=None):
6161
"X-Api-Key": self.api_key,
6262
}
6363

64-
if self.api_version >= (2, 0, 0):
65-
conn = httplib.HTTPSConnection(self.url)
66-
else:
67-
conn = httplib.HTTPConnection(self.url)
68-
'''Only GET is supported by the API at this time'''
69-
conn.request('GET', path, None, headers)
70-
71-
result = conn.getresponse()
64+
result = urllib2.urlopen(urllib2.Request(
65+
self.url + path, headers=headers,
66+
))
7267

73-
if result.status is not 200:
74-
conn.close()
75-
self.handleresponseerror(result.status)
68+
if result.getcode() is not 200:
69+
self.handleresponseerror(result.getcode())
7670

7771
resultdata = result.read()
78-
conn.close()
7972

8073
jsondata = json.loads(resultdata)
8174

0 commit comments

Comments
 (0)