MarketSquare / robotframework-requests

Robot Framework keyword library wrapper for requests

Home Page:http://marketsquare.github.io/robotframework-requests/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unsupported Media Type error

alex7alves opened this issue · comments

commented

I have the following json file:

{
   "company":[
      {
         "name":"My company",
         "security":"WPA2-PSK"
      }
   ],
   "name":"one name"
}

I'm trying to send a POST based on this json file but it's getting an error.

My code looks like this:

Create new company
    ${json1} =  Get file  create.json
    ${json} =   Evaluate  json.dumps(${json1})
    ${body} =  Evaluate  json.loads('''${json}''')  json
    Create Session    http_session   ${url}   disable_warnings=${True}
    ${response} = POST On Session   http_session  ${company}  data=${body}

But I get the following error:

POST Response:
headers={'content-type': 'application/json', 'vary': 'Accept, Origin, Cookie', 'allow': 'GET, POST, HEAD, OPTIONS', 'x-frame-options': 'DENY', 'content-length': '52', 'x-content-type-options': 'nosniff', 'referrer-policy': 'same-origin', 'set-cookie': '64bc588b56c7114f53411b945693e29ba=55323dcbd60f99b6aa8cfcb0f44f578e; path=/; HttpOnly; Secure; SameSite=None'} 
 body={"detail":"Unsupported media type \"\" in request."} 

HTTPError: 415 Client Error: Unsupported Media Type for url: 

I made this request using python requests and it worked.

If I pass the content of json directly in data it works too. But if I use a variable the error is shown.

commented

It was a problem in converting json. I did it like this:

${body} = Evaluate json.loads("""${json}""")
Now it worked.

You could pass the dictionary to json= parameter instead of data to let requests convert to json

commented

Thanks, doing like this: json=${body} solved my problem better.