'Robot framework: UnicodeEncodeError: 'ascii' codec can't encode characters in position

I have issue running curl command in Robot framework containing UTF-8 symbols:

Run And Return Rc And Output curl -H "Content-Type: application/json; charset=utf-8" -X POST -d '{"user_name":"User_ÈØ","password":"abc123"}' "https://test.com/test/prov/account"

This result in error:

UnicodeEncodeError: 'ascii' codec can't encode character

I am using robotframework 4.1.3; robotframework-seleniumlibrary 5.1.3; python 3.6.8



Solution 1:[1]

You can use following keyword to get this working: First you can put your data into variable with encoding string to byte and then pass it to POST.

${bytes} =  Encode String To Bytes  ${string}   UTF-8   
${bytes} =  Encode String To Bytes  ${string}   ASCII   errors=ignore

More detailed documentation is at - https://robotframework.org/robotframework/latest/libraries/String.html#Encode%20String%20To%20Bytes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sujit Neb