I have a test suite for an rest api that I implemented over the Requests Library, and it was working fine.
Last week, a new version of this library was released and I got some warnings regarding to deprecated keywords such post request, get request and others.
So I started to migrate the old implementation to the new one.
But with the new version, I an unable to pass a json to a simple post request.
I used to pass the json as a dictionary, but for some reason the body of the request is always None.
Currently, my keyword has the following implementation:
I Send a Post Request
[Arguments] ${alias} ${uri} ${data}=None ${json}=None ${msg}=None ${headers}=${EMPTY} ${timeout}=${EMPTY}
${kwargs} Create Dictionary
${hasValue} Run Keyword and return status Should not be empty ${headers}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} headers=${headers}
${hasValue} Run Keyword and return status Should not be empty ${timeout}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} timeout=${timeout}
${response}= Post On Session ${alias} ${uri} data=${data} json=${json} expected_status=any msg=${msg} &{kwargs}
Set Test Variable ${response}
When executed in a test, it sends and get as response:
POST Request : url=http://localhost:8080/logon
path_url=/logon
headers={'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Authorization': 'Bearer ******', 'X-Session-ID': '', 'X-Flow-ID': 'd933b413-1681-4eaf-9fee-ae4c3d82b9d8', 'X-Device-Info-UUID': '217ff7f7-1cb8-4760-8f52-35cdead8b1e0', 'X-Customer-ID': '123456', 'Content-Length': '4'}
body=None
POST Response : url=http://localhost:8080/logon
status=415, reason=
headers={'Accept': 'application/json', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Frame-Options': 'DENY', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Date': 'Mon, 01 Feb 2021 15:16:20 GMT', 'Keep-Alive': 'timeout=60', 'Connection': 'keep-alive'}
body={“timestamp”:“2021-02-01T12:16:20.568563-03:00”,“message”:“Content type ‘’ not supported”,“error”:“Unsupported Media Type”,“status”:415,“path”:"/logon"}