python - python27发布请求失败
问题描述
我使用此代码登录baiscopelk.com
- 在 Python 3.6 中,
print(res_1) == <Response [302]>
- 但在 Python 2.7 中我得到
print(res_1) == <Response [403]>
我无法理解问题
import requests
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.baiscopelk.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3) AppleWebKi'
't/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': 'https://www.baiscopelk.com/wp-login.php',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'si,en;q=0.9,en-US;q=0.8',
}
data = {
'log': 'baiscopelk.username',
'pwd': 'baiscopelk.password',
'wp-submit': 'Log In',
'redirect_to': 'https://www.baiscopelk.com/wp-admin/',
'testcookie': '1'
}
res_0 = requests.get('https://www.baiscopelk.com/wp-login.php', headers=headers)
res_1 = requests.post('https://www.baiscopelk.com/wp-login.php', headers=headers, data=data, cookies=res_0.cookies,
allow_redirects=False)
print(res_1)
解决方案
推荐阅读
- python - 如何在meshio中将颜色数组添加到网格?
- html - 如何让视频加载到 Github Pages html 上?
- javascript - 如何在映射数组之前等待设置状态?
- flutter - 当我的类扩展 GetView 时如何更新 ListView
- flutter - 如何使用 grideview.bulder 生成 8 个圆形头像小部件
- influxdb - 不断变化的分组
- c++ - C++ 中的 std::cin 内部会发生什么?
- html - 从网页中抓取链接
- django - 当我注销时,我发现此错误“详细信息”:“未提供身份验证凭据。”
- javascript - getServerSideProps 提供数据但不重新渲染