DinoTools / python-overpy

Python Wrapper to access the Overpass API
https://python-overpy.readthedocs.io/
MIT License
235 stars 58 forks source link

Support unverified SSL certificates #74

Open larsklitzke opened 5 years ago

larsklitzke commented 5 years ago
Issue type
Summary

I have a self hosted OpenStreetMap server which can only be accessed using SSL connections. The certificates are however generated using certbot and thus queries cannot be send using overpy due to the fact that those certificates are by default marked as unverified.

Hence, to fix this issue, I've added a new optional parameter context to the constructor of the Overpass object in order to define an optional ssl context which is passed to the call of urlopen in the query method.

So, if you want to connect to a Overpass server with a self signed certificate, create a new ssl context with:

ssl_context = ssl._create_unverified_context()

and setup a new Overpass object using that context

opy = overpy.Overpass(url='https://example.com/api/interpreter', context=ssl_context)

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.6%) to 93.998% when pulling bfced661137fccc164addb587d308ff3dddd609a on larsklitzke:master into db8f80eeb1b4d1405816bd62c16ddb3364e0c46d on DinoTools:master.

larsklitzke commented 5 years ago

Well, it seems that the context parameter for urlopen exists in 2.7.9 <= Python < 3 and was reintroduced in 3.4.3. Thus, the test builds for Python 3.0 - 3.3 are broken. This issue was also discussed on stackoverflow but the only answer was to upgrade Python.

So, either merge this patch to the master branch and applications using Overpy with a Python3 version of < 3.4.3 will break, create a new branch which only support Python > 3.3 or simply neglect that pull request.