RequestLibrary Post On session fail with "is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8."vs Post request pass

RequestLibrary Post On session fail with "is not valid Latin-1. Use body.encode(‘utf-8’) if you want to send it encoded in UTF-8."vs Post request pass
POST API
[Arguments] ${ENDPOINT} ${json} ${expected_status}
Create Session session ${API_BASE_URL}
${HEADERS} = create dictionary Content-Type=application/json Accept=application/json
${response}= POST On Session session ${API_BASE_URL}${ENDPOINT} headers=${HEADERS} data=${json}
${response_body}= Set Variable ${response.json()}
Log ${response_body}
[Return] ${response_body}

Hi @skoroghly,

My first thought was to try logging ${response.headers}, and look for the content-type header.

But then I looked closer at the error and it seems to be complaining that your request body is not utf-8.

Then I noticed this line:

${response}=  POST On Session  session ${API_BASE_URL}${ENDPOINT}  headers=${HEADERS}  data=${json}

Particularly the data=${json} part, which throws up several questions:

  • you don’t dell us what is in ${json} is it a json string?
  • should this post request send json data? if so what you might want is json=${json}? referr to the documentation for POST On Session and it’s reference to GET for the details on when you should use json or data
  • you also didn’t mention which version of RequestLibrary? are you updating a test that previously use an older version of RequestLibrary? I ask because there were quite a few changes to the keywords between v0.8.0 and now, so pay close attention to the documentation for the version you’re using.

Hopefully this helps,

Dave.

Hi @skoroghly,

From your answer I still have no idea whether ${json} is a string or dictionary?

400 bad request might be progress forward? does the response body say why it’s a bad request? does the server logs tell you anything?

At this point you need to compare what requests library is sending vs what the application is expecting, you may need to get some help from the app developer to tell you what’s wrong with your request.

As best I can tell json=${json} has resolved the encoding error and helped you progress to the json doesn’t match what the app wants, but I don’t know enough about your app to know for sure.

Dave.

1 Like

the issue fixed - json=${json} by use Load JSON From File or create dictionary
-string to json has isuue with encoding "non latine char "

1 Like