robotframework-requests icon indicating copy to clipboard operation
robotframework-requests copied to clipboard

Words pt-br with accents is causing 400 Bad Request on the new Post/Put On Session

Open mayribeirofernandes opened this issue 3 years ago • 4 comments

I'm migrating some tests with Get/Post/Put Requests to the new Get/Put/Post On Session, but I'm having difficulty with strings with accents (pt-br). See below in the image. What should I do?

image

Python 3.9.0 requests 2.25.1 requests-oauthlib 1.3.0 robotframework 4.0.2 robotframework-pythonlibcore 2.1.0 robotframework-requests 0.9.1

mayribeirofernandes avatar May 31 '21 13:05 mayribeirofernandes

That's most probably because you're using the data= parameter instead of json= try to swap those parameters.

lucagiove avatar Jun 07 '21 22:06 lucagiove

@lucagiove The same error occurred, however after I converted the String to JSON, it worked.

Alterar o livro "${ID_LIVRO}"
    # Na versão atual da Library Requests, o Put Request foi substituído por Put On Session
    # E foi acrescentado o argumento expected_status    
    ${JSON_BODY}     To Json    {"id":${BOOK_150.ID},"title":"${BOOK_150.Title}","description":"${BOOK_150.Description}","pageCount":${BOOK_150.PageCount},"excerpt":"${BOOK_150.Excerpt}","publishDate":"${BOOK_150.PublishDate}"}   
    ${RESPOSTA}      Put On Session  fakeAPI    Books/${ID_LIVRO}
    ...              json=${JSON_BODY}
    ...              headers=${HEADERS}  expected_status=any
    # ${RESPOSTA_2}    Put Request     fakeAPI    Books/${ID_LIVRO}
    # ...              data={"id":${BOOK_150.ID},"title":"${BOOK_150.Title}","description":"${BOOK_150.Description}","pageCount":${BOOK_150.PageCount},"excerpt":"${BOOK_150.Excerpt}","publishDate":"${BOOK_150.PublishDate}"}
    # ...              headers=${HEADERS}
    Log            ${RESPOSTA.text}
    Set Test Variable    ${RESPOSTA}

mayribeirofernandes avatar Jun 11 '21 16:06 mayribeirofernandes

Can I reproduce it with the fakeapi url you pasted? Would mind create a Pull Request with a failing test?

lucagiove avatar Jun 11 '21 17:06 lucagiove

https://github.com/MarketSquare/robotframework-requests/pull/335

mayribeirofernandes avatar Jun 12 '21 13:06 mayribeirofernandes