HTTPError: 500 Server Error: Internal Server Error for url

*** Settings ***
Documentation To Test API’S With Robot Framework
Library RequestsLibrary
Library Collections
Library JSONLibrary
Resource Resources/login_details.robot

*** Variables ***
${ALLOW_REDIRECTS} True

*** Test Cases ***
Login To ESS

&{json_data} =    Create Dictionary       clientId=${clientId}        username=${username}       password= ${password}
&{head} =         Create Dictionary       Content-Type=application/json
${body}             Evaluate               json.dumps(${json_data})       json
${ses}      create session         mysession       ${Base_URL}             verify=false
${response} =       POST On Session    mysession             endpoint       json=${body}      headers=${head}
log         ${response.json()}

#Assertion
Status Should Be 200 ${response}

Thanks for posting some test case code.
We can just ignore it :slight_smile:

Hi Digvijay,

It’s not clear what your question is if there is one?

I’m guessing you got a http 500 error and were expecting to get something else? Or perhaps you were expecting to get the http 500 and don’t want that marked as a fail?

Dave.

Hi Dave, I was expecting 200 status code, but got 500 so not able to understand why it is not working…because same endpoint working with postman

Hi Digvijay,

OK there are few things you need to do:

  • look at the response body that came back with the http 500, well written applications will tell you exactly whats missing, but unfortunately well written applications are rare
  • next compare the request headers and request body from the POST On Session keyword’s log to the request headers and body that postman sends.
    The most common reasons for getting a http 500 error are:
    • something missing from the request body that the server requires
    • A request header is missing that the server requires
    • A cookie is missing that the server requires (cookies are in the request header)

Actually HTTP protocol is very simple it’s all clear text and and there only 3 things you need to check:

  • the request URL
  • the request body
  • the request headers

If you get all 3 right the request will give you the response you want.

Dave.

Did everything but still getting 500 internal error,

*** Settings ***
Documentation To Test API’S With Robot Framework
Library RequestsLibrary
Library Collections
Library JSONLibrary
Resource Resources/login_details.robot

*** Variables ***
${ALLOW_REDIRECTS} True

*** Test Cases ***
Login To ESS

&{json_data} =    Create Dictionary       clientId=${clientId}        username=${username}       password= ${password}
&{head} =         Create Dictionary       Content-Type=application/json
&{COOKIES}=       Create Dictionary       cookie1=value      cookie2=value
${body}=          Evaluate               json.dumps(${json_data})       json
${ses}=           Create Session         mysession       ${Base_URL}           verify=true         headers=${head}          cookies=${COOKIES}
${response} =     POST On Session    mysession            end point       json=${body}
log         ${response.json()}

#Assertion
Status Should Be 200 ${response}

Hi Digvijay,

Just showing your robot code with no context, Unfortunately no one is going to be able to help you, there is simply not enough information and we don’'t know your application or it’s site specific implementation details.

Can you show the working request headers and request body from Postman as well as the ones sent by Robot Framework that failed, then I might be able to work out what’s missing or what the issue might be.

Dave.

Hi Digvijay,

Ok comparing them a couple of things I noticed

&{json_data} =    Create Dictionary       clientId=${clientId}        username=${username}       password= ${password}

There is a space before ${password} hopefully that’ not in your script?

&{COOKIES}=       Create Dictionary       cookie1=value      cookie2=value

Hopefully this is actually something like

&{COOKIES}=       Create Dictionary       idsrv=value      idsrv.session=value

Then there is your POST

${response} =     POST On Session    mysession            end point       json=${body}

I think you need to replace json=${body} with json=${json_data} and comment out the line

${body}=          Evaluate               json.dumps(${json_data})       json

Other than that it looks like it should be the same

Are the cookie values reusable or do they need to be regenerated for each request? That’s the only other thing I see.

Dave.

Hi Dave,
How can we regenerate cookies values for each new request?

Thank you so much Dave, it is sorted

1 Like