Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1854

Bad Requests 400 | Trying to login into JouetClub site | Python requests

$
0
0

I want login into jouetclub site in python, with requests only. My requests login response say 400, and i don't find any problem in my payload or my headers. any tips ?

import requestsimport jsonimport timeimport reimport sysimport osfrom requests import Requestfrom bs4 import BeautifulSoupfrom utils import random_agentfrom twocaptcha import TwoCaptchaclass RequestsJouetClubLogin :   def __init__(self, email, password):    self.email = email    self.password = password    # req session #    global session, headers    session = requests.Session()    agent = random_agent.random_user_agent()    headers = {'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.7','Accept-Encoding' : 'gzip, deflate, br, zstd','Accept-Language' : 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7','Cache-Control' : 'max-age=0','User-Agent' : agent,'Origin' : 'https://www.joueclub.fr',    }def get_login_data(self): """    get ids"""    #func extracting json    def getting_json_data(data):"""        return        1 websiteid        2 sectionid        3 pageid"""        data = json.loads(data)        navig = data['blockParameters']['headSeo']        page_id = navig['pageId']        navig = data['navigationContext']        website_id = navig['websiteId']        section_id = navig['sectionId']        return website_id, section_id, page_id     # PREPARED REQUESTS #    access_site_req = Request(        method='GET',        url='https://www.joueclub.fr/contenu/identification.html',        headers=headers    )    preparedrequests = session.prepare_request(access_site_req)    # TRYING REQUESTS #    try :        req = False        r = session.send(preparedrequests, timeout=10)        if r.status_code == 200 :            req = True            pass        else :            print(r.text)            print(r.status_code)    except TimeoutError :        print('requests timeout')        return False    except Exception as e :        print(f'Error : {e}')    if req == True :        # FOUND IDS #        soup = BeautifulSoup(r.text, 'html.parser')        #find correct script id#        x = 1        found_id = False        while True :            try :                 data_id = soup.find_all('script', {'type' : "text/javascript"})[0+x]                if re.match(r'<script type="text/javascript">\s*window\.__change\s*=', str(data_id)) :                    found_id = True                    break                else :                     x+=1            except :                return False        # getting information into json #         if found_id == True :            data_id = data_id.get_text()            data_id = data_id.strip()            data_id = data_id.replace('window.__change = ','')            data_id = data_id[:-1]            data_id = getting_json_data(data_id)            return data_id def login(self):    data = self.get_login_data()    websiteId = int(data[0])    sectionId = int(data[1])    pageId = int(data[2])    # payload #    login_payload = {"websiteId":websiteId,"sectionId":sectionId,"pageId":pageId,"data":{"login":"fdgfd@gmail.com","password":"dgffgd","realm":"web","rememberMe":True,"device":"Chrome - Windows","captchaToken":"token","isV2":False},"referer":"https://www.joueclub.fr/joueclub/mon-compte.html"}    login_payload = json.dumps(login_payload, separators=(',', ':'), indent=None)    # update headers #    headers['Sec-Ch-Ua'] = "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"    headers['Sec-Ch-Ua-mobile'] = '?0'    headers['Sec-Ch-Ua-platform'] = "Windows"    headers['Sec-Fetch-Dest'] = 'empty'    headers['Sec-Fetch-Mode'] = 'cors'    headers['Sec-Fetch-Site'] = 'same-origin'    headers['Accept'] = 'application/json, text/plain, */*'    headers['Content-Lenght'] = '1255'    headers['Referer'] = 'https://www.joueclub.fr/joueclub/mon-compte.html'    headers['Content-Type'] = 'application/json'    # remove not necessary headers #    del headers['Cache-Control']    # prepared login requests #    login_post_requests = Request(        method='post',        url='https://www.joueclub.fr/ajax.V1.php/fr_FR/Rbs/User/Login',        headers=headers,        json=login_payload,    )    login_prep_request = session.prepare_request(login_post_requests)    # send login requests #    rsp = session.send(login_prep_request, timeout=10, allow_redirects=True)    if rsp.status_code == 400 :        print('Always bad requests | zebiiiiii')    else :         print(rsp.text, rsp.status_code)

got : {"error":true,"code":"BAD-REQUEST","message":"Bad request"} | 400my payload was exactly the same, headers too

login page site : https://www.joueclub.fr/joueclub/mon-compte.htmllogin api : https://www.joueclub.fr/ajax.V1.php/fr_FR/Rbs/User/Login

if u have an idea pls tell me !thanks a lot


Viewing all articles
Browse latest Browse all 1854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>