I am accessing a webpage which creates a cookie with a value, and then modify this value and access another page from the same website.
Using librequests in python I got the following cookie:
s is a session opened with s = requests.Session()
In [63]: s.cookies
Out[63]: <RequestsCookieJar[Cookie(version=0, name='my_cookie', value='normal_value', port=None, port_specified=False, domain='my_domain.lol', domain_specified=False, domain_initial_dot=False, path='/my_path', path_specified=False, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False)]>
I tried several things with requests, first:
[74]: s.cookies.set('my_cookie','new_value')
Out[74]: Cookie(version=0, name='my_cookie', value='new_value', port=None, port_specified=False, domain='/mydomain.lol', domain_specified=False, domain_initial_dot=False, path='/my_path', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
but in return I got
In [75]: s.cookies
Out[75]: <RequestsCookieJar[Cookie(version=0, name='my_cookie', value='new_value', port=None, port_specified=False, domain='/mydomain.lol', domain_specified=False, domain_initial_dot=False, path='/my_path', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False),
Cookie(version=0, name='my_cookie', value='new_value', port=None, port_specified=False, domain='mydomain.lol', domain_specified=False, domain_initial_dot=False, path='/my_path', path_specified=False, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False)]>
As you can see, my new value did not replace the old one be created a new cookie, the same result was obtained using:
s.cookies['my_cookie'] = 'new_value'
I then tried specifying as many things as I could when setting my cookie and it worked :
In [67]: s.cookies.set('my_cookie','new_value',domain='mydomain.lol',path='/my_path')
Out[67]: Cookie(version=0, name='my_cookie', value='new_value', port=None, port_specified=False, domain='mydomain.lol', domain_specified=True, domain_initial_dot=False, path='/my_path', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
In [68]: s.cookies
Out[68]: <RequestsCookieJar[Cookie(version=0, name='my_cookie', value='new_value', port=None, port_specified=False, domain='mydomain.lol', domain_specified=True, domain_initial_dot=False, path='/my_path', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)]>
Therefore my question, isn't there a more convinient way of setting a cookie without specifying so many things? By getting the first cookie of my array for example?