通过POST man,REST调用工作正常,因此我通过postman本身生成了python代码,并执行了以下代码。但是我收到错误消息“无法检查CSRF令牌。请重试” 有人可以帮我弄清楚这里发生了什么吗?
import requests, re
url = "https://openshiftnew.com/oauth/token/request"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
'Authorization': "Basic ###########",
'Accept-Encoding': "gzip, deflate"
}
response = requests.request("GET", url, headers=headers, verify=False)
m = re.findall('value.*',response.text)
code = m[0].split('"')[1]
csrf = m[1].split('"')[1]
url = "https://openshiftnew.com/oauth/token/display"
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"code\"\r\n\r\n{code}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"csrf\"\r\n\r\n{csrf}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--".format(code=code, csrf=csrf)
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'Content-Type': "application/x-www-form-urlencoded",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.3",
'Authorization': "Basic ########",
'Cache-Control': "no-cache",
'Host': "openshiftnew.com",
'Accept-Encoding': "gzip, deflate",
'Cookie': "csrf={csrf}".format(csrf=csrf),
'Connection': "keep-alive",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers, verify=False)
print(response.text)
上面的代码尝试向OpenShift URL提交多部分表单数据请求