python - get cookie expiry time using the requests library -


i trying expiry time of specific cookie retrieve server as:

s = requests.session() r = s.get("http://localhost/test") r.cookies 

this list cookies sent server (i 2 cookies) as:

<<class 'requests.cookies.requestscookiejar'>[<cookie phpsessid=cusa6hbtb85li8po argcgev221 localhost.local/>, <cookie websecu=f localhost.local/test>]> 

when do:

r.cookies.keys 

i get:

<bound method requestscookiejar.items of <<class 'requests.cookies.requestscooki ejar'>[cookie(version=0, name='phpsessid', value='30tg9vn9376kmh60ana2essfi3', p ort=none, port_specified=false, domain='localhost.local', domain_specified=false , domain_initial_dot=false, path='/', path_specified=true, secure=false, expires =none, discard=true, comment=none, comment_url=none, rest={}, rfc2109=false), co okie(version=0, name='websecu', value='f', port=none, port_specified=false, doma in='localhost.local', domain_specified=false, domain_initial_dot=false, path='/test', path_specified=false, secure=false, expires=1395491371, discard=fals e, comment=none, comment_url=none, rest={}, rfc2109=false)]>> 

as can see, have 2 cookies. expiry time of cookie named "websecu"

thank you

in requests, cookie jar special object. might notice if do:

r.cookies['websecu'] 

you'll receive value of cookie string (in example f). actual cookie object holds information, have iterate on cookie jar so:

expires = none cookie in r.cookies:     if cookie.name == 'websecu':         expires = cookie.expires 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -