python - Python - POST 请求时拒绝访问 403
问题描述
我有 python 发送一个 POST 请求,如下所示,尽管我收到 403 Access Denied。我什至加入了代理(我知道网站上没有禁止),但我似乎仍然遇到同样的错误。
data = {'authToken': '3040141554%2CbCFq3TBCs6HpcoS4y8%2B%2FtD2wmOeTYUvjNs%2FEy9nQ94E%3D',
'actionType': 'add',
'formName': 'createFamilyUser',
'layout': 'user/createFamilyUser',
'storeId': '18',
'langId': '-26',
'addressType': 'SB',
'customerPanelInDB': 'false',
'ppAction': 'createFamilyUser',
'firstName': 'First',
'lastName': 'Last',
'birthDay': '4',
'birthMonth': '2',
'birthYear': '2000',
'address1': '123 Test St',
'city': 'Test City',
'state': 'QLD',
'zipCode': '1234',
'email1': 'xxxx@gmail.com',
'email1_verify': 'xxxx@gmail.com',
'phone2': '0420657499',
'logonPassword': 'Password123#',
'logonPasswordVerify': 'Password123#',
'storeNumber': '919',
'acceptCond': 'true'}
proxies = {'http': 'http://MyProxyHere', 'https': 'http://MyProxyHere'}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0'}
r = requests.post('https://secure.ikea.com/webapp/wcs/stores/servlet/ProtectedCreateUser', data=data, proxies=proxies, headers=headers)
print(r.status_code) # Prints 200
print(r.text)
它在我的终端返回:
403
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://secure.ikea.com/webapp/wcs/stores/servlet/ProtectedCreateUser" on this server.<P>
Reference #18.6367a5c.1556763656.439c5486
</BODY>
</HTML>
我实际上是在尝试在宜家创建一个帐户。我知道我的代理没有被禁止,因为我可以使用 selenium 在前端创建一个帐户,它工作得很好,但是通过这种方法它非常慢。对于此问题的解决方法,我们将不胜感激任何帮助...
解决方案
身份验证令牌将始终更改,因此您无法保留它。
以下代码应该可以工作:
import requests
import lxml
session = requests.Session()
data = {'storeId': '12',
'langId': '-1',
'from': 'null'}
response = session.post('https://secure.ikea.com/webapp/wcs/stores/servlet/CreateUser')
authToken = lxml.html.fromstring(response.content).xpath('//*[@id="createUser_authToken_In_Register_1"]')[0]
data = {'authToken': authToken,
'actionType': 'add',
'formName': 'createFamilyUser',
'layout': 'user/createFamilyUser',
'storeId': '18',
'langId': '-26',
'addressType': 'SB',
'customerPanelInDB': 'false',
'ppAction': 'createFamilyUser',
'firstName': 'First',
'lastName': 'Last',
'birthDay': '4',
'birthMonth': '2',
'birthYear': '2000',
'address1': '123 Test St',
'city': 'Test City',
'state': 'QLD',
'zipCode': '1234',
'email1': 'xxxx@gmail.com',
'email1_verify': 'xxxx@gmail.com',
'phone2': '0420657499',
'logonPassword': 'Password123#',
'logonPasswordVerify': 'Password123#',
'storeNumber': '919',
'acceptCond': 'true'}
proxies = {'http': 'http://MyProxyHere', 'https': 'http://MyProxyHere'}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0'}
r = session.post('https://secure.ikea.com/webapp/wcs/stores/servlet/ProtectedCreateUser', data=data, proxies=proxies, headers=headers)
推荐阅读
- html - 我网站的响应能力在 5SE 和 Galaxy Fold 上搞砸了
- android-emulator - Fiddler - 被捕获的 IP 地址而不是来自 android 模拟器的 URL
- java - 如何比较 application.yml 中的值
- android-management-api - 设备“memoryEvents”
- r - 使用 pickerInput 后的输出表没有显示,因为它应该使用 ShinyDashboard
- kubernetes - 运行 k3s-killall.sh 脚本后如何启动 K3s 服务器
- android - 无法删除 Google Play 发布错误。如何告诉 Google Play 我的应用不适用于 COVID 追踪?
- python - 遍历 Excel 行以从 Google 搜索中获取 URL 并将它们写入 Excel 的新列中
- python-3.x - 单选按钮和框架重叠 tkinter
- r - 使用 STAN 在 R 中的包 bmgarch 中出现错误消息:异常:验证转换后的参数:H[i_0__] 不是对称的