Skip to main content
Solved

Problem Regex in Python


danilo_fme
Evangelist
Forum|alt.badge.img+45

Hello FME User's,

I'm reading a Website ( http://www.rio.rj.gov.br/ ) and through the transformer PythonCaller using Regex to find a value from attribute _response_body.

When the Workspace was executed a error is happened like the information bellow:

Python Exception <UnicodeEncodeError>: 'ascii' codec can't encode character u'\\xd3' in position 315: ordinal not in range(128)

 

Attached my template file.

Thanks in Advance,

Danilo de Lima

 

Best answer by david_r

As a side note: If you struggle with those kind of errors in Python, consider switching to Python 3.x in FME, that tends to make it a lot easier.

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

3 replies

takashi
Influencer
  • July 7, 2017

Hi @danilo_inovacao, the response body is a utf-8 string, and utf-8 code set contains character codes which cannot be encoded to ascii code. It's the reason for the error. You should not encode the response body string.

And, although it's not a direct reason for the error, you are wrong on use of the re.compile method.. I therefore cannot understand what you intend to do with the re module.

See here to learn how to use the re module.

Python Documentation | 7.2. re — Regular expression operations


danilo_fme
Evangelist
Forum|alt.badge.img+45
  • Author
  • Evangelist
  • July 9, 2017
takashi wrote:

Hi @danilo_inovacao, the response body is a utf-8 string, and utf-8 code set contains character codes which cannot be encoded to ascii code. It's the reason for the error. You should not encode the response body string.

And, although it's not a direct reason for the error, you are wrong on use of the re.compile method.. I therefore cannot understand what you intend to do with the re module.

See here to learn how to use the re module.

Python Documentation | 7.2. re — Regular expression operations

Hi @takashi, thanks your help.

 

I believe that the method re.search is better to fin any words between two strings.

 

Thanks

 


david_r
Celebrity
  • Best Answer
  • July 10, 2017

As a side note: If you struggle with those kind of errors in Python, consider switching to Python 3.x in FME, that tends to make it a lot easier.


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