尽管我收到403 Access Denied,但我有python发送POST请求,如下所示。我什至合并了代理(我知道该站点上没有禁止代理),但似乎仍然出现相同的错误。
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>
我实质上是想在宜家创建一个帐户。我知道我的代理服务器没有被禁止,因为我可以使用硒在前端创建一个帐户,并且可以正常工作,但是通过这种方法非常慢。对于此问题的解决方法,我们将提供任何帮助...
答案 0 :(得分:0)
Auth令牌将始终更改,因此您无法持久保存它。
以下代码应该起作用:
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)