Skip to main content

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

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


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


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":"....."}


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?


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.


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)


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_MacroValuesV'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_MacroValuesF'My_Param']), In both cases it writes æøå. I have tried to encode and decode FME_MacroValuesd'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?


My suggestion to improve the Published text parameter


My suggestion to improve the Published text parameter

Or instead add the encoding to the configuration.

 

 


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_MacroValuest'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_MacroValuesE'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.

 


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.


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.

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?

 

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.

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

 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