Iconv_open failed for execute command stdout in log file

Hi all,

i run execute command from sshlibrary and want to check the output from stdout. In my log i see this “error”?

${stdout} = QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv_open failed
QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed

I just do a simple cat command of a file /tmp/foobar.txt which exists on the system.

Documentation: 	

Executes command on the remote machine and returns its outputs.
Start / End / Elapsed: 	20240730 10:57:10.377 / 20240730 10:57:10.614 / 00:00:00.237
10:57:10.377 	INFO 	Executing command 'cat /tmp/foobar.txt'. 	
10:57:10.614 	INFO 	Command exited with return code 0. 	
10:57:10.614 	INFO 	${stdout} = QIconvCodec::convertToUnicode: using Latin-1 for 
conversion, iconv_open failed
QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed
08:57:10:333 Info: Starting server of Sq... 	
10:57:10.614 	INFO 	${stderr} = 	
10:57:10.614 	INFO 	${rc} = 0

any ideas?

any ideas?

another example where i execute the command “squishserver --version”
It returns rc=0 and on stdout it returns the version which is 7.2.0 but on stderr it returns this iconv_open failed message - why?

Documentation: 	

Executes command on the remote machine and returns its outputs.
Start / End / Elapsed: 	20240730 12:35:17.904 / 20240730 12:35:18.016 / 00:00:00.112
12:35:17.904 	INFO 	Executing command 'squishserver --version'. 	
12:35:18.016 	INFO 	Command exited with return code 0. 	
12:35:18.016 	INFO 	${stdout} = 7.2.0 	
12:35:18.016 	INFO 	${stderr} = QIconvCodec::convertToUnicode: using Latin-1 for 
conversion, iconv_open failed 	
12:35:18.016 	INFO 	${rc} = 0

Hi Camil,

Is this with the SSHLibrary, Process Library, or another library?

The issue might be you need to set the encoding, if it’s SSHLibrary and you have slack see this message

Dave.

Hi Dave,

yes its the execute command keyword from the sshlibrary (version 3.8.0) - According to google its something with “Open Connection” where i have to set the encoding?
sadly i don’t have slack. can you post what i can/should do on here?

Thx
br,
camil

Hi Camil,

It can be done in Open Connection or when registering the Library,

The original question on slack was:

Hi Everyone
I would like to request for help in handling “‘UnicodeDecodeError: ’ utf-8’ codec can’t decode byte 0xc1 in position 0: invalid start byte.” Error seen while using ‘Sshlibrary.Read Until’ keyword… I am trying to read the console output and look for ‘login:’ prompt to enter the username but facing the above error. Appreciate any assistance to resolve the same.:slightly_smiling_face:

Here’s what I wrote on slack:

A quick search for “sshlibrary unicodedecodeerror” found this:
python - SSHLibrary UnicodeDecodeError: 'utf8' codec can't decode byte 0xa9 in position 660: invalid start byte - Stack Overflow indeed it’s in the documentation for SSHLibrary:
http://robotframework.org/SSHLibrary/SSHLibrary.html#Connections%20and%20login
Under the heading : Encoding

Argument encoding defines the character encoding of input and output sequences. The default encoding is UTF-8.

You can choose your encoding either when you import the library or when you open the connection, I guess you just need to find out what encoding your ssh server is using and make them match

If you’re still stuck reply here I’ll try to help

Dave.

Hi Dave,

thank you for pointing this out. The default encoding it UTF-8 which is fine i guess. I don’t see a reason to modify it. Also i use “Execute Command” from SSHLibrary quite often in different RF-Tasks. Some other example see here:

Documentation:	
Executes command on the remote machine and returns its outputs.

Start / End / Elapsed:	20240731 06:35:32.029 / 20240731 06:35:32.077 / 00:00:00.048
06:35:32.029	INFO	Executing command 'sed -i 'xxxxxxxxxx'	
06:35:32.076	INFO	Command exited with return code 0.	 
06:35:32.076	INFO	${stdout} = 	
06:35:32.076	INFO	${stderr} = 	
06:35:32.076	INFO	${rc} = 0

So here i’m using “sed…” command on the remote host. The command exit with rc=0 and here i don’t have any message on stderr.

The only difference is that the command with “sed…” runs on a different host. So could it be because of my host?

br,
camil

Hi Camil,

I’m not sure why your getting the error, perhaps the squishserver command expects a Latin-1 console, so the error might be coming from that command rather than SSHLibrary?

I suggest try connecting with that encoding and see if it resolves the issue.

if the other commands like sed give you an error with Latin-1 encoding then you may need to maintain 2 connections depending on the command you need to run.

You might also want to raise an issue with the developer of squishserver that their app doesn’t support utf-8 as every application should support utf-8 these days.

Dave.

Hi Dave,

i will check for the squishserver --version command. It’s strange that i see this error in stderr.
For now i don’t care about the error as im only intrested in the stdout and rc.

The other commands i execute like “sed” does not throw this error - the stderr is empty.

Br,
Camil

Hi Camil,

The other person on slack didn’t care about the encoding errors either, so their solution was to just pass encoding _errors=ignore to SSHLibrary when they imported the library

Library                SSHLibrary                encoding _errors=ignore

The default for encoding _errors is strict, with the other options being ignore and replace the characters it can’t encode.

So that might be an option for you too? but as your error seems to be coming from squishserver, I’m not sure how much that will help.

I’d suggest still capture the stderr but knowing it has that error, don’t do anything other than log it, and add a comment in the test that the convertToUnicode error is a known issue, or maybe not even log it unless ${rc} is not 0, only because if you get an error stderr might have some other useful information.

Dave.

1 Like