0

I am trying to make a simple POST to the API but keep getting Attribute Error: 'str' object has no attribute 'items'. I have tried using a different API to make a POST request and it works without any problems. The difference was that it didn't require header information.

*** Settings ***
Library     RequestsLibrary
Library     Collections
Library     OperatingSystem

*** Variables ***
${baseUrl}      https://simple-books-api.glitch.me
${headers}      Content-Type=application/json;charset=utf-8   Authorization=Bearer 9daaef9d38b7bff40af6400bba8fffb7a466e778ecd3068d9a9766d231491bc2


*** Test Cases ***
OrderBook
create session  mysession   ${baseUrl}  verify=true
${body}=    create dictionary       bookId=1  customerName=John Doe
LOG TO CONSOLE     ${body}
${response}=    post on session    mysession   /orders     data=${body}    headers=${headers}
log to console  ${response}

log to console    ${response.status_code}
log to console    ${response.content}

#validations
${res_body}=    convert to string   ${response.content}
should contain    ${res_body}   true

1 Answer 1

2

The issue came from the way you defined the ${headers} variable - in the Variables section you need to prefix with & to get a dictionary. Just change it to this and it should be fine:

*** Variables ***
${baseUrl}      https://simple-books-api.glitch.me
&{headers}      Content-Type=application/json;charset=utf-8   Authorization=Bearer 9daaef9d38b7bff40af6400bba8fffb7a466e778ecd3068d9a9766d231491bc2
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for helping out, it worked! I also had to change data=${body} to json=${body}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.