Skip to main content
Question

FME Server - Published parameter as utf-8 or unicode?


sigtill
Contributor
Forum|alt.badge.img+24

It seems FME Server needs unicode in the request - to for instance fmedatadownload, and if sending utf-8 it fails.

For instance *fmedatadownlad/myrepository/myworkspace.fmw?myparameter=Bærre lækkert

But this will work:

fmedatadownlad/myrepository/myworkspace.fmw?myparameter=B%C3%A6rre%20l%C3%A6kkert

17 replies

mark2atsafe
Safer
Forum|alt.badge.img+43

Hi @sigtill

I did a little research and it may be a browser problem. ie the browser should encode those characters in a URL style when it sends the request to FME Server. Have you tried a different browser? It might not help as a solution, but it would perhaps show whether the problem is browser-specific.

Another clue would be in the URL provided in the 'developer info' part of the FME Server web interface. Is the information correctly encoded there (as %C3%A6)? Or is it incorrect there too? If it's incorrect there then I definitely think it's an FME issue.

Does that help? If not I suggest you contact our support team and ask for assistance. They should be able to tell you where the source of the problem is.

Regards

Mark


david_r
Evangelist
  • May 20, 2016

Hi Sigbjørn

UTF-8 is actually just a way of representing Unicode.

What you've stumbled upon is what's called URL Encoding, or Percent Encoding, which is pretty well explained in the wikipedia article.

If you need to convert to/from URL Encoding inside a workspace, look at the TextEncoder transformer.

In Javascript you can use the built-in functions encodeURIComponent() and decodeURIComponent() to accomplish the same thing.

David


Forum|alt.badge.img
  • May 20, 2016

Mark2AtSafe:

The situation described by Sigtill is a bit more complex.

We are calling the datadownload through C#-code server-side, relevant code here: https://gist.github.com/atlefren/722660e2112d6660b...

As far as I understand everything related to charset is OK before the actual POST request is sent to FME server, but in the generated pdf our service creates the characters æøå are simply dropped, while standard ascii characters are printed as expected.

Yet stranger, when looking at the status page for the FME server, the request sent from our C#-code actually has æøå, and they are printed fine on the webpage, as FME_SERVER_REQUEST_PARAMETERS

{"opt_responseformat":"json","opt_requesteremail":"....","Buffer":"20","Overskrift":"Test æøå!","opt_servicemode":"async","geomPolygon":"....."}


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • May 20, 2016
a4 wrote:

Mark2AtSafe:

The situation described by Sigtill is a bit more complex.

We are calling the datadownload through C#-code server-side, relevant code here: https://gist.github.com/atlefren/722660e2112d6660b...

As far as I understand everything related to charset is OK before the actual POST request is sent to FME server, but in the generated pdf our service creates the characters æøå are simply dropped, while standard ascii characters are printed as expected.

Yet stranger, when looking at the status page for the FME server, the request sent from our C#-code actually has æøå, and they are printed fine on the webpage, as FME_SERVER_REQUEST_PARAMETERS

{"opt_responseformat":"json","opt_requesteremail":"....","Buffer":"20","Overskrift":"Test æøå!","opt_servicemode":"async","geomPolygon":"....."}

Hi @a4, in my experiences, there are cases that the PDF writer cannot write non-ascii characters. If you run the workspace with Workbench, those characters will be written into a pdf doc correctly?


sigtill
Contributor
Forum|alt.badge.img+24
  • Author
  • Contributor
  • May 24, 2016
takashi wrote:

Hi @a4, in my experiences, there are cases that the PDF writer cannot write non-ascii characters. If you run the workspace with Workbench, those characters will be written into a pdf doc correctly?

Hi takashi - PDF is written OK when run from FME Desktop and FME Servers web-interface (www.myfmeserverurl.com/fmeserver) - so the error is as mentioned by a4 when calling the workspace through c#-code serverside.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • May 25, 2016
a4 wrote:

Mark2AtSafe:

The situation described by Sigtill is a bit more complex.

We are calling the datadownload through C#-code server-side, relevant code here: https://gist.github.com/atlefren/722660e2112d6660b...

As far as I understand everything related to charset is OK before the actual POST request is sent to FME server, but in the generated pdf our service creates the characters æøå are simply dropped, while standard ascii characters are printed as expected.

Yet stranger, when looking at the status page for the FME server, the request sent from our C#-code actually has æøå, and they are printed fine on the webpage, as FME_SERVER_REQUEST_PARAMETERS

{"opt_responseformat":"json","opt_requesteremail":"....","Buffer":"20","Overskrift":"Test æøå!","opt_servicemode":"async","geomPolygon":"....."}

hmm, I'm not sure the exact reason, but guess that FME Server interprets the encoded parameters with the default encoding of its platform, which may not be UTF-8.

It might be worth to try specifying the encoding explicitly to the second argument of the "System.Net.WebUtility.UrlEncode" method in your C# code.

HttpUtility.UrlEncode Method (String,?Encoding)


paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 19, 2017

I'm having a similar issue when calling a published parameter within a python scripted parameter in FME Desktop. Lets say I have a return line in my script like this: return 'æøå', this works fine, but when I try to return a published parameter containing 'æøå' like this: return FME_MacroValues['My_Param'], FME 2017.0.2 stops, no crash report or nothing. When printing the two values, print 'æøå' shows æøå, but print FME_MacroValues['My_Param'] shows. <?><?><?>. If I write both of them to a text file, like this txt= 'C:\\\\temp\\\\test.txt' with open(txt,'w') as t: t.write('æøå') t.write(FME_MacroValues['My_Param']), In both cases it writes æøå. I have tried to encode and decode FME_MacroValues['My_Param'].encode('UFT-8') and iso-8859-1 with no luck. I think there might be something with the coding of published parameters, but I am out of ways to solve this now. Anyone knows how to get pass this?


paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 19, 2017

My suggestion to improve the Published text parameter


paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 19, 2017
paalped wrote:

My suggestion to improve the Published text parameter

Or instead add the encoding to the configuration.

 

 


david_r
Evangelist
  • May 19, 2017
paalped wrote:

I'm having a similar issue when calling a published parameter within a python scripted parameter in FME Desktop. Lets say I have a return line in my script like this: return 'æøå', this works fine, but when I try to return a published parameter containing 'æøå' like this: return FME_MacroValues['My_Param'], FME 2017.0.2 stops, no crash report or nothing. When printing the two values, print 'æøå' shows æøå, but print FME_MacroValues['My_Param'] shows. <?><?><?>. If I write both of them to a text file, like this txt= 'C:\\temp\\test.txt' with open(txt,'w') as t: t.write('æøå') t.write(FME_MacroValues['My_Param']), In both cases it writes æøå. I have tried to encode and decode FME_MacroValues['My_Param'].encode('UFT-8') and iso-8859-1 with no luck. I think there might be something with the coding of published parameters, but I am out of ways to solve this now. Anyone knows how to get pass this?

FME automatically applies a "wrapper" around your scripted parameters, which unfortunately, casty your return string into a non-unicode 'str' object. Example: if you create a published parameter called "my_favorite_letters" and it contains "return u'æøå'", the auto-generated wrapper will look like this

 

def ParamFunc():
  return u'æøå'

value = ParamFunc()
macroName = 'my_favorite_letters'
if value == None:
  return { macroName : '' }
else:
  return { macroName : str(value) }
Notice how the last line casts 'value' as a non-unicode 'str' object. Using Python 2.x this will create an exception and FME will terminate (or in some instances hang, it seems)

 

 

The problem is that FME 2017 does not seem to take the selected Python interpreter into account when wrapping the scripted parameter, it always casts as 'str' even though Python 3.x by default will treat all strings as a 'unicode' object.

 

 

So as far as I can tell, the conlusion is that FME scripted parameters currently cannot be anything but a 'str' object, i.e. not a 'unicode' object.

 


david_r
Evangelist
  • May 19, 2017

I've posted the following idea which you can vote for:

https://knowledge.safe.com/idea/44684/python-scripted-parameters-must-be-able-to-return.html

This would fix the encoding issues when returning a unicode string in a Python scripted parameter.


david_r
Evangelist
  • May 19, 2017
paalped wrote:

My suggestion to improve the Published text parameter

Personally I think the encoding should always be unicode, it would be simpler and you wouldn't have to specify the encoding.

 

For scripted parameters, it's possible for FME to infer the returned data type using code introspection, which would render the encoding parameter superfluous.

paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 19, 2017
david_r wrote:

I've posted the following idea which you can vote for:

https://knowledge.safe.com/idea/44684/python-scripted-parameters-must-be-able-to-return.html

This would fix the encoding issues when returning a unicode string in a Python scripted parameter.

 

The link is broken. Did it get removed immediately?

david_r
Evangelist
  • May 19, 2017
paalped wrote:

 

The link is broken. Did it get removed immediately?
Takashi made me aware of an error in an assumption I made and I've retracted the idea. In fact, I think it's a bug (that FME crashes when scripted parameters return certain characters) and I'll report it as such.

paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 19, 2017

 I found an odd solution to my own question:

import base64
letters = FME_MacroValues['My_Favourite_Letters']
return base64.b64encode(letters)

This actually solves the whole problem. I thought I had to convert this back to ascii with the BinaryEncoder Transformer with base64, but I didn't need to. It was allready encoded correctly.


david_r
Evangelist
  • May 19, 2017
paalped wrote:

 I found an odd solution to my own question:

import base64
letters = FME_MacroValues['My_Favourite_Letters']
return base64.b64encode(letters)

This actually solves the whole problem. I thought I had to convert this back to ascii with the BinaryEncoder Transformer with base64, but I didn't need to. It was allready encoded correctly.

Very interesting, thanks for sharing.

paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 19, 2017
paalped wrote:

 I found an odd solution to my own question:

import base64
letters = FME_MacroValues['My_Favourite_Letters']
return base64.b64encode(letters)

This actually solves the whole problem. I thought I had to convert this back to ascii with the BinaryEncoder Transformer with base64, but I didn't need to. It was allready encoded correctly.

I'm sorry, I had to use the BinaryDecoder Transformer with Base64 unicode(iso-8859-1) to be able to retrieve the data in workbench.

 

Late friday here.

Reply


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