question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeEncodeError when geocoding result contains non-ASCII character

See original GitHub issue

When trying to encode an address whose result would contain a non-ASCII character (e.g. é, á, ž etc.), I get this error. Using iPython 2.7 in Anaconda on Windows 7. Any ideas? Thanks for the great library BTW!

In [58]: s = geocoder.bing("Champs de Mars, Paris", proxies=proxies)

In [59]: s
Out[59]: <[OK] Bing - Geocode [Champ de Mars, Paris, France]>

In [60]: s = geocoder.bing("Avenue Champs Elysees, Paris", proxies=proxies)
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-60-62b4e3a20efb> in <module>()
----> 1 s = geocoder.bing("Avenue Champs Elysees, Paris", proxies=proxies)

C:\Documents\SW\Anaconda\lib\site-packages\geocoder\api.pyc in bing(location, **kwargs)
    205         > reverse
    206     """
--> 207     return get(location, provider='bing', **kwargs)
    208
    209

C:\Documents\SW\Anaconda\lib\site-packages\geocoder\api.pyc in get(location, **kwargs)
    101                   '>>> g = geocoder.get([45.68, -75.15], method="reverse
")')
    102             sys.exit()
--> 103     return options[provider][method](location, **kwargs)
    104
    105

C:\Documents\SW\Anaconda\lib\site-packages\geocoder\bing.pyc in __init__(self, location, **kwargs)
     65             'maxResults': 1,
     66         }
---> 67         self._initialize(**kwargs)
     68         self._bing_catch_errors()
     69

C:\Documents\SW\Anaconda\lib\site-packages\geocoder\base.pyc in _initialize(self, **kwargs)
     99         self._build_tree(self.content)
    100         self._exceptions()
--> 101         self._json()
    102
    103     def _json(self):

C:\Documents\SW\Anaconda\lib\site-packages\geocoder\base.pyc in _json(self)
    105             if bool(not key.startswith('_') and key not in self._exclude
):
    106                 self.fieldnames.append(key)
--> 107                 value = getattr(self, key)
    108                 if value:
    109                     self.json[key] = value

C:\Documents\SW\Anaconda\lib\site-packages\geocoder\bing.pyc in housenumber(self)
    105             expression = r'\d+'
    106             pattern = re.compile(expression)
--> 107             match = pattern.search(str(self.street))
    108             if match:
    109                 return match.group(0)

UnicodeEncodeError: 'ascii' codec can't encode character u'\xc9' in position 18:
 ordinal not in range(128)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jvsteinercommented, Jun 7, 2016

I’m getting this issue with:

loc = geocoder.google(u'Dubultu iela 9, Riga, LV-1029')
print loc

Update: Issue seems to be with the loc.address property:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/path/to/project/venv/lib/python2.7/site-packages/geocoder/base.py", line 62, in __repr__
    six.text_type(self.address)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u012b' in position 32: ordinal not in range(128)
1reaction
martinfthomsencommented, Feb 4, 2016

It is good to hear you are interested in fixing it. =) I also made a manual correction in base.py line 62 to fix an encoding problem there:

    def __repr__(self):
        if self.address:
            return "<[{0}] {1} - {2} [{3}]>".format(
                self.status,
                self.provider.title(),
                self.method.title(),
                six.text_type(self.address).encode('utf8')
                # six.text_type(self.address)
            )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Geocoding address involving non-ASCII characters in ...
The problem is that the returned address contains non-ASCII characters. Any ideas to solve this? from geopy.geocoders import Nominatim #Next, we ...
Read more >
Confusion with unicode in Python
First, check if addressString is a Unicode object (it is if you're using Python 3, or if type(addressString) shows 'unicode').
Read more >
Changelog of the 0.9 series — GeoPy 2.3.0 documentation
CHANGED: Geocoders' geocode and reverse method return types have changed from None, a tuple, or a list of tuples, to None, a geopy.Location ......
Read more >
Stata Module for Forward and Reserve Geocoding
variables to be in Unicode (UTF-8). That is address names may contain accented characters, symbols and non-latin characters. For older releases, the input ......
Read more >
CSV, TXT, and GPX files—Portal for ArcGIS
For example, address and ZIP Code will yield better results than just address. ... If you import an ASCII-encoded file containing non-English characters, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found