Python-403在POST请求时拒绝访问
我让python发送了一个POST请求,如下所示,尽管我收到了403个拒绝访问的请求。我甚至加入了代理(我知道这在网站上是不被禁止的),但我似乎仍然得到同样的错误Python-403在POST请求时拒绝访问,python,python-3.x,post,python-requests,Python,Python 3.x,Post,Python Requests,我让python发送了一个POST请求,如下所示,尽管我收到了403个拒绝访问的请求。我甚至加入了代理(我知道这在网站上是不被禁止的),但我似乎仍然得到同样的错误 data = {'authToken': '3040141554%2CbCFq3TBCs6HpcoS4y8%2B%2FtD2wmOeTYUvjNs%2FEy9nQ94E%3D', 'actionType': 'add', 'formName': 'createFamilyUser', '
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>
403
拒绝访问
拒绝访问
您无权访问此服务器上的“http:;/;/;安全.;宜家.;com/;webapp/;wcs/;商店/;servlet/;受保护的CreateUser”。
参考文献 #18.6367a5c.;1556763656.439c5486
我基本上是想在宜家建立一个账户。我知道我的代理没有被禁止,因为我可以使用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)
身份验证令牌可能已过期。他们不会告诉你出了什么问题,因为这不是他们期望的用法。祝您好运。您是否尝试在
标题中使用authToken,而不是在数据中使用authToken?我认为authToken常用于header@ShioT尝试使用新的auth token,但仍然没有成功:/@Jin Yep也尝试了,仍然返回403…您可能必须使用CreateFamilyUser
表单获取页面,才能获得隐藏在HTML中的新的authToken
。您可能还需要Session()
来保存cookie。服务器可能会将authToken
与一些cookie进行比较。然后,您可以使用此authToken和表单中隐藏的其他值尝试POST。看起来不错,但我的行authToken=lxml.html.fromstring(response.content.xpath('/*[@id=“createUser\u authtToken\u in\u Register\u 1”]”的索引列表超出了范围[0]