Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions pyPostcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'''


import httplib
import urllib2
import json
import logging

Expand All @@ -33,9 +33,9 @@ def __init__(self, api_key, api_version=(2, 0, 0)):
self.api_key = api_key
self.api_version = api_version
if api_version >= (2, 0, 0):
self.url = 'postcode-api.apiwise.nl'
self.url = 'https://postcode-api.apiwise.nl'
else:
self.url = 'api.postcodeapi.nu'
self.url = 'http://api.postcodeapi.nu'

def handleresponseerror(self, status):
if status == 401:
Expand All @@ -61,21 +61,14 @@ def request(self, path=None):
"X-Api-Key": self.api_key,
}

if self.api_version >= (2, 0, 0):
conn = httplib.HTTPSConnection(self.url)
else:
conn = httplib.HTTPConnection(self.url)
'''Only GET is supported by the API at this time'''
conn.request('GET', path, None, headers)

result = conn.getresponse()
result = urllib2.urlopen(urllib2.Request(
self.url + path, headers=headers,
))

if result.status is not 200:
conn.close()
self.handleresponseerror(result.status)
if result.getcode() is not 200:
self.handleresponseerror(result.getcode())

resultdata = result.read()
conn.close()

jsondata = json.loads(resultdata)

Expand Down