VertNet / api-geospatial

Code for the Geospatial Data Quality REST API for Primary Biodiversity Data
GNU General Public License v2.0
5 stars 2 forks source link

Check out country name encoding #6

Open jotegui opened 8 years ago

jotegui commented 8 years ago

Found out that Côte d'Ivoire is messing the API up:

?decimalLatitude=&decimalLongitude=&countryCode=C%C3%B4te%20d'Ivoire&scientificName=Typhlops%20punctatus
'ascii' codec can't encode character u'\xf4' in position 1: ordinal not in range(128)
Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~vertnet-portal/api-geospatial:prod.391042971109842700/geospatial/GeospatialIssue.py", line 33, in get
    data = urlencode(params)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib.py", line 1307, in urlencode
    v = quote_plus(str(v))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 1: ordinal not in range(128)
tucotuco commented 8 years ago

Maybe try the following?

'countryCode': self.request.get('countryCode').decode('latin-1').encode('utf-8')

at https://github.com/VertNet/api-geospatial/blob/master/geospatial/GeospatialIssue.py#L29