Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

Python Session update cookies

Update: I let-rally tried 12 suggested solutions but nothing worked at all. Is my question missing any details? The suggested answer doesn't solve the problem

In python I wrote:

print(s.cookies.get_dict())

where s is my session, the output is:

{'lubl': 'https%3A%2F%2Fopenworld.com%2Fconfirm', 'rishum': 'SHjshd2398-'}

Now my question is how can I edit rishum cookie such that I want to append 'test' next to it (or to make things simple replace it by 'test')?

For example, I want:

'rishum': 'SHjshd2398-test'

Note: as someone suggested I tried the following but didn't work:

print(s.cookies.get_dict())
s.cookies.get_dict()['rishum'] = 'test'
print(s.cookies.get_dict())

output before and after is:

{'lubl': 'confirm', 'rishum': 'SUqsadkjn239s8n-', 'PHPSESSID': 'nfdskjfn3k42342', 'authchallenge': 'asjkdnjnkj34'}

{'rishum': 'SUqsadkjn239s8n-', 'lubl': 'confirm', 'PHPSESSID': 'nfdskjfn3k42342', 'authchallenge': 'asjkdnjnkj34'}

Note the order has changed.

question from:https://stackoverflow.com/questions/65871734/python-session-update-cookies

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The way i understood from your question, s is json file that equals to

s = {'lubl': 'https%3A%2F%2Fopenworld.com%2Fconfirm', 'rishum': 'SHjshd2398-'}

than if you want to add 'test' to the end of 'rishum', you need to do the following

s['rishum'] = s['rishum'] + 'test' 

and than

print(s)

I believe your mistake was that you called function twice, that's why you saw same answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...