Reputation: 1188
I want to test API using Requests Library.
My Code is as follows:
*** Settings ***
Documentation Read API Testcase
Library RequestsLibrary
*** Variables ***
${headers} {'content-type': 'application/json', 'authorizationFlag':'N'}
*** Test Cases ***
Read API
Create Session CLM http://172.20.33.224:8080/clm-reg/rest/dataservice/1/CLM/1
${resp} Get Request CLM /RegistrationRequestDetails/json/583d8b14498e021b2f93a773 headers = ${headers}
Log to console ${resp}
I am getting the error :
AttributeError: 'unicode' object has no attribute 'items'
I found the problem with the Headers i am passing.
when i searched over the internet, i got that the way i am passing the header values is correct.
Please any one help me on this.
Thanks Sarada
Upvotes: 2
Views: 14620
Reputation: 462
You could use the built-in variable dictionary type like this:
Set Test Variable ${HEADERS} Content-Type=application/json authorisationFlag=N Accept=*/* Cache-Control=no-cache
Then call it as a variable which spread as a dict on your headers variable:
${resp} Post Request api-encoder /api-token-auth/ data=${DATA} headers=${HEADERS}
Upvotes: 0
Reputation: 141
I tried several methods on Robot Framework 5.0.1 (Python 3.11.3 on darwin), below code works:
${HEADERS} Create Dictionary
Set To Dictionary ${HEADERS} Content-Type=application/json accept=*/*
Upvotes: 0
Reputation: 2126
I've changed your headers line to what should work. Let us know if you've any success or what other problems you get tripped up on.
*** Variables ***
${headers} Create Dictionary Content-Type application/json authorisationFlag N
Upvotes: 2
Reputation: 1849
The problem is that your ${headers}
var is just a string, not a dictionary.
JSON is tricky that way. You have several options to create a dictionary in RF.
Create Dictionary
keywordjson.loads(str)
as a lib callEvaluate
keyword...Upvotes: 1