Skip to main content
Solved

Error biuld URL in PythonCaller

  • June 28, 2017
  • 4 replies
  • 12 views

danilo_fme
Celebrity
Forum|alt.badge.img+51

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

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

Bom Dia @danilo_inovacao,

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


danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • June 28, 2017

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
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • June 28, 2017

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

Danilo Lima