From 94aeceb8944e709e66754c33a913204d20ae63c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Mon, 9 Apr 2018 19:04:24 +0200 Subject: [PATCH] Fixes encoding --- .../cartodb_services/tomtom/geocoder.py | 12 ++++++++++++ .../cartodb_services/test/test_tomtomgeocoder.py | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py index 783be25..432dd31 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py @@ -1,3 +1,6 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- + import json import requests from uritemplate import URITemplate @@ -62,6 +65,15 @@ class TomTomGeocoder(Traceable): @qps_retry(qps=5) def geocode(self, searchtext, city=None, state_province=None, country=None): + if searchtext: + searchtext = searchtext.decode('utf-8') + if city: + city = city.decode('utf-8') + if state_province: + state_province = state_province.decode('utf-8') + if country: + country = country.decode('utf-8') + if not self._validate_input(searchtext, city, state_province, country): return [] diff --git a/server/lib/python/cartodb_services/test/test_tomtomgeocoder.py b/server/lib/python/cartodb_services/test/test_tomtomgeocoder.py index 7fcfcda..002847a 100644 --- a/server/lib/python/cartodb_services/test/test_tomtomgeocoder.py +++ b/server/lib/python/cartodb_services/test/test_tomtomgeocoder.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import unittest from mock import Mock from cartodb_services.tomtom import TomTomGeocoder @@ -5,7 +7,7 @@ from cartodb_services.tools.exceptions import ServiceException from credentials import tomtom_api_key INVALID_APIKEY = 'invalid_apikey' -VALID_ADDRESS = 'Plaza Mayor 3, Valladolid' +VALID_ADDRESS = u'ManterĂ­a 3, Valladolid'.encode('utf-8') class TomTomGeocoderTestCase(unittest.TestCase):