samedi 1 mai 2021

Akamai 403 acced denied

I'm trying to write a code that login into Zalando website. When I do login request AKAMAI GHOST server block me with error 403 access denied.

Below the code, someone can help me ?

import time
import requests
from bs4 import BeautifulSoup
import json
import logging

logging.basicConfig(level=logging.DEBUG)


# all cookies received will be stored in the session object
s = requests.Session()

url='https://www.zalando.it'

####### First request function ##################################################################
headers = {
    'authority': 'www.zalando.it',
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'sec-fetch-site': 'none',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-user': '?1',
    'sec-fetch-dest': 'document',
    'accept-language': 'it',
}
response = s.get(url, headers=headers)
st_code=response.status_code
url_text=response.text
resp_header_fr=response.headers
ck=s.cookies
#print(ck)
#print(st_code)
##################################################################################################

######### extract token
cookies_dictionary = ck.get_dict()
json_object = json.dumps(cookies_dictionary)
d2 = json.loads(json_object)

#print('token....')
#print('lets go!')
token=(d2["frsx"])
#print(token)


########### extract il client-id
json_object = json.dumps(cookies_dictionary)
d2 = json.loads(json_object)

#print('Client-id....')
#print(d2["Zalando-Client-Id"])
#print('lets go!')
client_id=(d2["Zalando-Client-Id"])
##############################################################################

## Delay 2 sec
time.sleep(2)

##############################################################################

####### Login request function ###################################################################
headers = {
    'authority': 'www.zalando.it',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
    'x-xsrf-token': token,
    'x-zalando-render-page-uri': '/login',
    'x-zalando-client-id': client_id,
    'content-type': 'application/json',
    'x-zalando-request-uri': '/login',
    'accept': 'application/json',
    'x-zalando-toggle-label': 'THE_LABEL_IS_ENABLED',
    'sec-ch-ua-mobile': '?0',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
    'origin': 'https://www.zalando.it',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://www.zalando.it/login',
    'accept-language': 'en-GB,en;q=0.9',
}
data = '{"username":"Email@gmail.com","password":"Password!","wnaMode":"modal"}'
url_login = 'https://www.zalando.it/api/reef/login'
response2 = s.post(url_login, headers=headers, data=data)
st_code=response2.status_code
ck2=s.cookies
url02_text=response2.text
resp_header_login=response2.headers

#Print cookie and response code

#print(ck)
print(st_code)
print(url02_text)
#print(resp_header_login)

if I run the same code with cookie and token taken from chrome browser, it work. I thin that Akamai detect that its not a web chrome session and not allow me to login.




Aucun commentaire:

Enregistrer un commentaire