Skip to main content
Solved

Error biuld URL in PythonCaller


danilo_fme
Evangelist
Forum|alt.badge.img+44

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

Best answer by david_r

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

View original
Did this help you find an answer to your question?

4 replies

mygis
Supporter
Forum|alt.badge.img+13
  • Supporter
  • June 28, 2017

Bom Dia @danilo_inovacao,

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


danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Author
  • Evangelist
  • June 28, 2017
mygis wrote:

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 :)

david_r
Celebrity
  • Best Answer
  • June 28, 2017

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


danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Author
  • Evangelist
  • June 28, 2017

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

Danilo Lima


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings