Solved

Error biuld URL in PythonCaller


Userlevel 4
Badge +30

Hello Team,

My workspace has a transformer HTTPCaller that send request to googlemaps API without problem, its works!

I want to demonstrate my customer that is possible to build this URL and send request to googlemaps using python ( PythonCaller ).

import fme
import fmeobjects
import json,urllib
from urllib import urlencode
import googlemaps
import re


REMOVE_HTML_TAGS= r'<[^>]+>'


def _googlemaps_(feature):
    
    url = 'https://maps.googleapis.com/maps/api/directions/json?%s' % urlencode((
    ('origin',feature.getAttribute('inicio')),
    ('destination',feature.getAttribute('destino')),('waypoints=optimize:true|',feature.getAttribute('waypoints'))
))


    resultado = json.load(urllib.urlopen(url))
    
    print url

When i run my Workspace the URL result has special caracters and doenst works my request:

https://maps.googleapis.com/maps/api/directions/json?origin=+Av%2B+Mal%2BFloriano%2B168%2BCentro%2BRio%2Bde%2BJaneiro+%2BRJ&destination;=+Av%2B+Mal%2BFloriano%2B168%2BCentro%2BRio%2Bde%2BJaneiro+%2BRJ&waypoints;%3Doptimize%3Atrue%7C=R%2BFARME%2BDE%2BAMOEDO%2B56%2BIPANEMA%7CR%2BNASCIMENTO%2BSILVA%2B4%2BIPANEMA

How can i configurated in python to dont generate these special caracteres?

Thanks in Advance,

Danilo

icon

Best answer by david_r 28 June 2017, 15:54

View original

4 replies

Badge +8

Bom Dia @danilo_inovacao,

Just to satisfy my FMist curiosity, why don't you use the string concatenator ?

Userlevel 4
Badge +30

Bom Dia @danilo_inovacao,

Just to satisfy my FMist curiosity, why don't you use the string concatenator ?

Hi @gisinnovationsb, thanks your quicly reply.

 

I tried with before the transformer PythonCaller use the StringConcatenator and its works.

 

My goal is show this concatenate using Python.

 

Thanks :)
Userlevel 4

With Python 2.x it's a royal hassle mixing strings and unicode sequences. If your version of FME allows, consider switching to Python 3.x where these issues have been dealt with.

If you're stuck with Python 2.x, please see the attached template for an example.

google-geocode.fmwt

Userlevel 4
Badge +30

Hello @david_r, thanks your help and excellent explanation about this difference between Python versions.

Danilo Lima

Reply