HTTPS and ca_cert with JSON Post using Requests

868 views
Skip to first unread message

afrizen

unread,
Oct 26, 2017, 12:46:34 AM10/26/17
to robotframework-users

I am trying to test an HTTPS API with Robot Framework and cannot get a post request to suceed. It involves HTTPS, a security certification, json data. Based on the tests (https://github.com/bulkan/robotframework-requests/blob/master/tests/testcase.txt), it should be simple. But no combination of session create verify, post request verify, list or dictionary header combos seems to satisfy the RF-RequestLibrary to spit back results. 


Debug from RF log shows: "post response: {"error":{"code":401,"message":"Missing Basic Authorization Header"}}" with all combos. What am I missing?

Robot Framework API Post Test1
	&{data}=    Create Dictionary   any....@yourcorp.com 
	Create Session    mysession    https://<our-secret-url>		
	&{auth}= 	Create Dictionary 	authorization 	"Basic <secret>"   verify=${CERTDIR}/cacert.pem	
	${resp}=  Post Request  mysession  / 	auth=${auth}	params=${data} 	
	Should Be Equal As Strings  ${resp.status_code}  200
Robot Framework API Post Test2
	&{data}=    Create Dictionary   any....@yourcorp.com 
	Create Session    mysession    https://<our-secret-url>		verify=${CERTDIR}/cacert.pem
	&{auth}= 	Create Dictionary 	authorization 	"Basic <secret>" 	
	${resp}=  Post Request  mysession  / 	auth=${auth}	params=${data} 	
	Should Be Equal As Strings  ${resp.status_code}  200
Robot Framework API Post Test3
	&{data}=    Create Dictionary   any....@yourcorp.com 
	Create Session    mysession    https://<our-secret-url>		verify=${CERTDIR}/cacert.pem
	${auth}= 	Create List 	authorization 	"Basic <secret>" 	
	${resp}=  Post Request  mysession  / 	auth=${auth}	params=${data} 	
	Should Be Equal As Strings  ${resp.status_code}  200

...etc. etc....

Frustratingly, Postman, cURL and the Requests library in Python have absolutely no problem:

===================== Request Library return results !

import requests
url = "https://<our-secret-url>"
payload = "{\"email\":\"any....@yourcorp.com\"}"
headers = {
	'content-type': "application/json",
	'authorization': "Basic <secret>",
	'cache-control': "no-cache",
	'postman-token': "<secret>"
	}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)

===================== cURL return results!

curl -X POST \
  https://<our-secret-url> \
  -H 'authorization: Basic <secret>' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: <secret>' \
  -d '{"email":"any....@ourcorp.com "}'

Help before I'm forced to abandon Robot Framework!

Wlad

unread,
Oct 26, 2017, 5:43:45 AM10/26/17
to afr...@me.com, robotframework-users
try to use "Create Dictionary key=value key2=value2" for &{auth} ... also execute test with "-L TRACE" command line option and check log.html after run to verify that you provide correct headers and body to the request. It's just a matter of syntax which might be a bit tricky to figure out for the first time ;-) Cheers
Tset

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Wlad

unread,
Oct 26, 2017, 5:52:19 AM10/26/17
to afr...@me.com, robotframework-users
you did not provide andy headers in your robot code like you did in all the other examples (requests, curl, ...)

&{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded ${resp}= Post Request httpbin /post data=${data} headers=${headers}

Reply all
Reply to author
Forward
0 new messages