steffex / pypostcode Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for the API of postcodeapi.nu
License: MIT License
Python wrapper for the API of postcodeapi.nu
License: MIT License
would be nice to have it installable via pip
Eventually the version 2 of Postcode API will get deprecated, it will need to be updated to allow to use v3.
Update in march when version 1 will be shutdown
Perhaps an implementation issue in postcodeapi.nu itself, but I've not yet found how the API is to differentiate between "1185ZH/7/G" and "1185ZH/7/G/BIS" (see https://www.postcode.nl/1185ZH/7/G with 43m2 and https://www.postcode.nl/1185ZH/7/G%20BIS with 32m2)
Instead, the API seems to return (with "view=bag" added) in both cases the id="0362010002002946" VBO; which can be queried for via https://service1.kadaster.nl/bag/bag-burger/secured/selectie, using "Verblijfsobject" (VBO) and the id above... showing that it belongs to "1185ZH/7/A"
Looking at the (current) "bag-adressen-bagaveen.csv.gz" file downloaded from http://data.nlextract.nl/bag/csv/; it shows that "VBO 0362010002002951"="1185ZH/7/G" and "VBO 0362010002182896"="1185ZH/7/G/BIS"; which can be confirmed by above Kadaster search feature... and note how the m2 values match the postcode.nl checks.
To me it seems like postcodeapi.nu is (incorrectly) ignoring "huisletter" and "huisnummertoevoeging" when parsing the BAG extract (and I assume that they use similar files like the ones that can be obtained from http://data.nlextract.nl/bag/csv/ (maybe more directly from the source agencies). It appears that their implementation always returns the first "7" found (or perhaps imported?) and ignoring any further detailing.
Now, as said, this might be due to me not correctly reading the API documentation for this service at http://api.postcodeapi.nu/docs/resources/housenumber
Hey Stefan,
I cannot find the pyPostcode 0.2 on https://pypi.python.org.
Do you still have to push this?
FYI / FWIW:
On Ubuntu 14.04.5 LTS (with Python 2.7.6) the example.py does not work. See below.
The error
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
is a common problem with older python versions in combination with TLS and possibly SNI (Server Name Indication). So far I have not found a solution or workaround within python 2.7.6.
With python 2.7.11 it works fine.
It's easy to reproduce with three lines of code:
$ python
Python 2.7.6 (default, Oct 26 2016, 20:32:47)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> req = urllib2.Request("https://postcode-api.apiwise.nl/")
>>> resp = urllib2.urlopen(req)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Output of example.py with Python 2.7.6:
sander@haring:~/postcode-API/git_postcodeapi$ python example.py
ERROR:root:<urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Traceback (most recent call last):
File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 99, in getaddress
data = self.request(path)
File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 65, in request
self.url + path, headers=headers,
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
ERROR:root:<urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Traceback (most recent call last):
File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 99, in getaddress
data = self.request(path)
File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 65, in request
self.url + path, headers=headers,
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Traceback (most recent call last):
File "example.py", line 7, in <module>
print result.street
AttributeError: 'bool' object has no attribute 'street'
With python 2.7.11 it works fine:
sander@haring:~/postcode-API/git_postcodeapi$ /opt/python2711/bin/python example.py
De Ruijterkade
125
1011AC
Amsterdam
Amsterdam
Noord-Holland
52.3776421
4.9066958
122281
487861
De Ruijterkade
154
1011AC
Amsterdam
Amsterdam
Noord-Holland
52.3772667
4.9094314
122467
487818
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.