2
2
Fork
You've already forked overpass-api-python-wrapper
2

no unicode for csv #99

Closed
opened 2018年06月28日 16:25:52 +02:00 by m-rieke · 3 comments
m-rieke commented 2018年06月28日 16:25:52 +02:00 (Migrated from github.com)
Copy link

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

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 <module> > 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

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.

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](https://repl.it/@mvexel/VioletPushyUtilities)). 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.

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

(The `csv` module documentation has [an example](https://docs.python.org/2/library/csv.html#csv-examples) using a generator function to make this work (however this is probably lossy).

Can you confirm this still reproduces on current versions? Please include the minimal query and CSV output that shows the unicode issue.

Can you confirm this still reproduces on current versions? Please include the minimal query and CSV output that shows the unicode issue.
Sign in to join this conversation.
0.8.x
main
tutorial/d1-httpx-nvim
0.8.x
dev-contributor-tooling
1.0-dev
dev
feature/api-modernization
maintenance/base-0.8
maintenance/geojson-fixtures
archive/async-models
maintenance/endpoint-guard
maintenance/live-query-tool
maintenance/modernize-plan
archive/dev-prebaseline-20260502
archive/modernize
archive/chore-tests
chore/poetry
archive/readme
v0.8.2
v0.8.1
v0.8.0
v0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.4.0
0.1.0
0.0.2
0.0.1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mvexel/overpass-api-python-wrapper#99
Reference in a new issue
mvexel/overpass-api-python-wrapper
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?