Don’t use SessionAsync


If you are trying to write a Cinnamon extension/applet and having this error when trying to parse some data that you have fetched via Soap.SessionAsync:

Failed to convert UTF-8 string to JS string: Invalid byte sequence in conversion input

Using Soap.Session instead of Soap.SessionAsync may solve your problem.

I’ve encountered this problem when working with StackExchange API which always returns data in compressed format regardless of request headers. It turns out Soap.SessionAsync doesn’t automatically decode data according to its encoding headers. You have to initiate decoding explicitly.

Or you could just use Soap.Session which handles decoding as you would expect.

I’ve wanted to write this because due to historic reasons all of the -already small number of- Javascript Soap library usage examples is written with SessionAsync class. For simple purposes though Session class can be used which is capable of handling both synced and asynced requests.

 


Leave a Reply

Your email address will not be published.