Skip to main content

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

 

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 @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

 


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.


Reply