Get Set-Cookie in header using requests module

心已入冬 提交于 2020-02-06 03:04:28

问题


When I use PHP to get cookie, it returns:

session_id=abih14s7l4lgo3splta7f6bd14; cccaa78fa9e13785130119a4924db0f4=96637ae... (more)

But when I use Python, it returns:

session_id=abih14s7l4lgo3splta7f6bd14

... the rest of cookies is lost.

My code Python:

res_post = requests.post(LOGIN_URL, data = {mydata})
cookies = dict(res_post.cookies.items())

回答1:


Looks like you're using the requests library. The response.cookies is already a dictionary, so there's no need to cast it again.

You should access the cookies on the response like so:

response = requests.post(LOGIN_URL, data={mydata})
print response.cookies['session_id']

See here for more detail: http://docs.python-requests.org/en/latest/user/quickstart/#cookies



来源:https://stackoverflow.com/questions/34113005/get-set-cookie-in-header-using-requests-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!