使用python请求发送cookie

时间:2018-09-12 16:05:31

标签: python-3.x python-2.7 python-requests

我正在尝试使用python的requests模块发出发布请求。 我将headerscookiesdata作为发布请求的一部分传递。
当我发出请求时,我在输出中得到400 bad request。 我验证了有效载荷,对我来说看起来正确。我想知道我的cookie语法是否正确。

#!/usr/local/bin/python
import requests

session = "ASDFGHTR/=FGHYTYKSDMN="
lastmanaged = "9ycG9yYXRpb25fRGlyZWN0I"  

header = {'akm-accept':'akm/cookie'}

cookie = {'SESSION': session,
         'LASTMANAGED':lastmanaged}

data = {'client': '0ad3cfb66-4fa0-b94a-1bf712eae628&grant_type=password_assertion'}

url = "https://hostname-goes-here" 

session = requests.Session()
response = session.post(url, headers=header, cookies=cookie, data=data, 
            verify=False, allow_redirects=False)


print(response.text)
print(response.status_code)

输出:

{"code":"invalid_request","title":"One or more fields in request are invalid","incidentId":"f1fbba64-17e4-4d88-852f-01c137fa012e","requestId":"-5011561246754340090","solution":"none"}
400

0 个答案:

没有答案