Loading
Subject: Authentication Issue with API - 400 Error "Cookie Missing"

Hello everyone,

I'm encountering a problem while attempting to authenticate with a specific API. After following the official documentation to establish a connection and sending an authentication request using Python's 'requests' library, I consistently receive a 400 error with the following message: '{"error": {"code": "400.002.002", "description": "Cookie Missing"}}'.

Here is a simplified snippet of my code:

'''python

import requestsimport json

 

Charger les paramètres à partir du fichier JSONs = json.load(open("settings.json", "r", encoding="utf-8"))

 

Extraire le nom d'utilisateur et le mot de passeusername = s['REVENERA']['USER']password = s['REVENERA']['PASSWORD']

 

Extract header valuescontent_type = s['headers']['Content-Type']rui_client = s['headers']['RUI-Client']rui_client_version = s['headers']['RUI-Client-Version']origin = s['headers']['Origin']

 

 

user = {    "user": username,    "password": password}

 

Setup the headers dictionaryheaders = {        "Content-Type": content_type,    "RUI-Client": rui_client,    "RUI-Client-Version": rui_client_version,    "Origin": origin   }

 

URL d'authentification de l'APIURL = "https://analytics-api.revenera.com/v3/auth/web "URL_V3 = "https://api.revulytics.com/auth/login "

 

Création d'une session pour maintenir les cookieswith requests.Session() as session:            Faire la requête d'authentification avec les en-têtes et le corps corrects        response = session.post(URL, json=user, headers=headers)        print(response.cookies)

 

        Vérifiez la réussite de l'authentification        if response.ok:            print("Authentification réussie")            L'ID de session et éventuellement d'autres données peuvent être extraits ici            session_id = response.json().get("sessionId")            print("ID de session :", session_id)        else:            print(f"Échec de l'authentification: {response.status_code} - {response.text}")

 

Exécuter la fonction d'authentification (Cette ligne sera décommentée dans le script final) authenticate_and_execute()   

'''

I ensure the session is initiated, and all headers required by the documentation are included. However, the error seems to indicate a missing cookie in my request, although the documentation does not explicitly mention the need for such a cookie for authentication.

Has anyone encountered this type of error before? Is there an additional step or a specific header I might have missed to transmit or receive the required cookie?

Any help or suggestion would be greatly appreciated.

Thank you in advance for your support.


Loading
Subject: Authentication Issue with API - 400 Error "Cookie Missing"