mvexel / overpass-api-python-wrapper

Python bindings for the OpenStreetMap Overpass API
Apache License 2.0
359 stars 89 forks source link

no unicode for csv #99

Open m-rieke opened 6 years ago

m-rieke commented 6 years ago

There is currently no way on using unicode in csv, this was working before 0.6.0:

import overpass

query_adminlevel = "\
area['int_name'='Nederland']->.searchArea;\
(\
    relation[boundary=administrative][admin_level=4]['ISO3166-2'~'NL'](area.searchArea);\
    );\
out center;"

api = overpass.API(timeout=1000)
overpass_adminlevel = api.Get(query_adminlevel, responseformat='csv(::"id", "name:en", "name", "int_name")')
print overpass_adminlevel

With 0.6.0 there is an error:

Traceback (most recent call last): File "test.py", line 14, in overpass_adminlevel = api.Get(query_adminlevel, responseformat='csv(::"id", "name:en", "name", "int_name")') File "/home/localuser/.local/lib/python2.7/site-packages/overpass/api.py", line 74, in get for row in reader: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in position 21: ordinal not in range(128)

I think it is because the default csv package does not support utf-8

mvexel commented 5 years ago

Hmm yes, good point. We could use some more unit testing for unicode related pitfalls existing in Python 2. I don't want to deprecate Python 2 support just yet, since many people still use it. Consider updating to Python 3 if you can (the code snippet works in Py3). I will keep this open as a bug, but unless someone wants to come up with a PR to fix I won't prioritize this.

mvexel commented 5 years ago

(The csv module documentation has an example using a generator function to make this work (however this is probably lossy).