Unfortunatly, i’m not a Python developer. I use RF by using keyword only…
An another way to correct this problem is existing ? I hope I’m not the only one who have this kind of problem lol.
I had a similar problem and I already had a keyword that implemented the post request. Then, I created a dictionary of arguments with the keyword Create Arguments Dictionary and called it in such keyword and passed the created dictionary to post on session.
In such dictionary you will find the jason, data and everything that can be sent to a request.
I Send a Post Request
[Arguments] ${alias} ${uri} ${data}=${EMPTY} ${json}=${EMPTY}
... ${params}=${EMPTY} ${headers}=${EMPTY} ${files}=${EMPTY}
... ${allow_redirects}=${EMPTY} ${timeout}=${EMPTY}
... ${kwargs} Create Arguments Dictionary data=${data} json=${json}
... params=${params} headers=${headers} files=${files}
... allow_redirects=${allow_redirects} timeout=${timeout}
${response}= Post On Session ${alias} ${uri} expected_status=any &{kwargs}
Set Test Variable ${response}
Create Arguments Dictionary
[Arguments] ${data}=${EMPTY} ${json}=${EMPTY} ${params}=${EMPTY} ${headers}=${EMPTY} ${files}=${EMPTY} ${allow_redirects}=${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}
${hasValue} Run Keyword and return status Should not be empty ${data}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} data=${data}
${hasValue} Run Keyword and return status Should not be empty ${params}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} params=${params}
${hasValue} Run Keyword and return status Should not be empty ${files}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} files=${files}
${hasValue} Run Keyword and return status Should not be empty ${allow_redirects}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} allow_redirects=${allow_redirects}
${hasValue} Run Keyword and return status Should not be empty ${json}
Run Keyword if ${hasValue} Set To Dictionary ${kwargs} json=${json}
[Return] ${kwargs}
I suggest to have a look on the server logs whether you get more information about the BAD REQUEST.
I think you can remove most of the headers part and pass json=.
Another point might be to properly convert the json file to a dictionary or something parsable from requests.