# 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

**URL:** <https://forum.robotframework.org/t/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/7666>\
**Category:** RequestsLibrary\
**Created:** [4 August 2024 13:07 UTC](https://forum.robotframework.org/t/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/7666 "2024-08-04T13:07:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skoroghly](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/skoroghly/32/4114_2.png) [@skoroghly](https://forum.robotframework.org/u/skoroghly)\
**Post date:** [4 August 2024 13:07 UTC](https://forum.robotframework.org/t/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/7666/1 "2024-08-04T13:07:37Z")

</div>

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}

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [5 August 2024 02:06 UTC](https://forum.robotframework.org/t/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/7666/2 "2024-08-05T02:06:29Z")

</div>

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:

```python
${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](https://marketsquare.github.io/robotframework-requests/doc/RequestsLibrary.html#POST%20On%20Session) and it’s reference to [GET](https://marketsquare.github.io/robotframework-requests/doc/RequestsLibrary.html#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.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [5 August 2024 14:12 UTC](https://forum.robotframework.org/t/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/7666/4 "2024-08-05T14:12:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![skoroghly](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/skoroghly/32/4114_2.png) [@skoroghly](https://forum.robotframework.org/u/skoroghly)\
**Post date:** [7 August 2024 08:55 UTC](https://forum.robotframework.org/t/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/7666/5 "2024-08-07T08:55:11Z")

</div>

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