Cookie is not working in robotframework-requests

1,684 views
Skip to first unread message

Beno K Immanuel

unread,
Oct 1, 2015, 1:01:59 AM10/1/15
to robotframework-users
Hi , 

we are trying to use the robotframework-requests for test web application using REST .. cant able to use the cookie of the login session after /login request .. 
any one can able to help in this issue ..

python : Python 2.7.8
pybot --version
Robot Framework 2.8.6 (Python 2.7.8 on win32)
>>> RequestsLibrary._version_
'0.3.8'

Here is my log :

KEYWORD: ${reply} = RequestsLibrary.Get Request session1, /mz/p/v1/troubleshoot/ping, headers=${sess_header}
Documentation:

Send a GET request on the session object found using the

Start / End / Elapsed:20151001 10:12:53.123 / 20151001 10:12:53.235 / 00:00:00.112
10:12:53.125INFOStarting new HTTPS connection (1): 10.58.133.101
10:12:53.202DEBUG"GET /mz/p/v1/troubleshoot/ping HTTP/1.1" 302 None
10:12:53.228DEBUG"GET /login.html HTTP/1.1" 200 2599

the request needs to go to the cookie  session its not going to cookie session...
setting cookie : {u'set-cookie': 'session=QwmuH2vBDxiCynjyoAgMKg.k64UgteMf7aCCCWeFg47TGY5Y3GnZqNANvTddE8ophk.1072916884715.7200000.yKoMdKcRMyN2HR9NkXnUA53KVxdQW0gqpVSf4eW0cE4; path=/; expires=Thu, 01 Jan 2004 02:28:05 GMT; secure; httponly'}

KEYWORD: BuiltIn.Log ${reply.headers}
Documentation:

Logs the given message with the given level.

Start / End / Elapsed:20151001 09:58:54.054 / 20151001 09:58:54.057 / 00:00:00.003
09:58:54.056INFO{'content-length': '2599', 'set-cookie': 'session=_VyumCKwR2Bql8V5FBb0pA.etmg7aCDEQ2Pt3xkKijb0txQtfL67rsmEf7RRwblk74.1072916045754.7200000.zP-iBvg_Wcm35JhmppsUTq7hwjRKmZIGTbUqPyCn1ls; path=/; expires=Thu, 01 Jan 2004 02:14:06 GMT; secure; httponly', 'expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'last-modified': 'Wed, 30 Sep 2015 16:34:39 GMT', 'connection': 'keep-alive', 'pragma': 'no-cache', 'cache-control': 'private, no-cache, no-store, must-revalidate, max-age=0, pre-check=0, post-check=0, public, max-age=3600', 'date': 'Thu, 01 Jan 2004 00:14:05 GMT', 'content-type': 'text/html'}

Here is my Testcase:

${headers}= Create Dictionary Content-Type application/json
${session} = Create Session session1 https://<server ip> headers=${headers}
${resp}= Post Request session1 /login data={"username":"<username>","password":"<password>"}
${session_cokie} = Create Dictionary set-cookie ${resp.headers['set-cookie']}
${sess_header}= Create Dictionary set-cookie ${resp.headers['set-cookie']} content-type application/json
${session} = Create Session session1 https://10.58.133.101 headers=${sess_header} cookies=${session_cokie}
Should Be Equal As Strings ${resp.status_code} 200
${reply}= Get Request session1 /mz/p/v1/troubleshoot/ping headers=${sess_header}

Regards,
Beno 

ankit mangal

unread,
Jan 27, 2016, 1:09:59 AM1/27/16
to robotframework-users
I am kind of working on the same thing and curious to know about it more..... 

Mallikarjunarao Kosuri

unread,
Jan 27, 2016, 7:40:14 AM1/27/16
to robotframework-users
Hi,

Cookies are part of HTTP headers, you are sending separately both cookies and headers instead try to send cookies as part of headers

For more information https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

http://tclscripting.blogspot.in/
Malli
Reply all
Reply to author
Forward
0 new messages