123ang
123ang

Reputation: 35

Python - 403 Access Denied When POST Request

I have python sending a POST request as can be seen below although I am receiving 403 Access Denied. I have even incorporated proxies (which I know are not banned on the site) but I still seem to be getting the same error.

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': '[email protected]',
        'email1_verify': '[email protected]',
        '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)

It is returning in my terminal:

403
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>

You don't have permission to access "http&#58;&#47;&#47;secure&#46;ikea&#46;com&#47;webapp&#47;wcs&#47;stores&#47;servlet&#47;ProtectedCreateUser" on this server.<P>
Reference&#32;&#35;18&#46;6367a5c&#46;1556763656&#46;439c5486
</BODY>
</HTML>

I am essentially trying to create an account on Ikea. I know my proxies aren't banned since I can create an account on the frontend using selenium and it works just fine however it is very very slow via that method. Any help would be appreciated as to a workaround for this problem...

Upvotes: 1

Views: 1684

Answers (1)

Attila Kis
Attila Kis

Reputation: 533

Auth token will always change, so you can't persist it.

The following code should work:

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': '[email protected]',
    'email1_verify': '[email protected]',
    '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)

Upvotes: 1

Related Questions