import requests
# 30d7b203e5c672987745da8986a5583720b63477c87df775是用户用来登录的token或者密码 headers = { 'Authorization': 'Token 30d7b203e5c672987745da8986a5583720b63477c87df775', "X-XSRFToken": "123" } login_url = "http://127.0.0.1:8888/login?next=%2F" r = requests.post(login_url, headers=headers, allow_redirects=False, data={'username': 'root', 'password': '30d7b203e5c672987745da8986a5583720b63477c87df775'}) r.raise_for_status() cookies = r.cookies print(cookies) print(cookies.values()[0])
运行结果如下所示: