From 7e8877df86727d7f3f201718bb64240a51f25a5b Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 10 Jun 2024 16:40:50 +0100 Subject: [PATCH] Use cookie to get csrf token in JSON API Login.py --- examples/Training/python/Json_Api/Login.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/Training/python/Json_Api/Login.py b/examples/Training/python/Json_Api/Login.py index 16abd379014..1107c27fdbc 100644 --- a/examples/Training/python/Json_Api/Login.py +++ b/examples/Training/python/Json_Api/Login.py @@ -35,9 +35,12 @@ save_url = urls['url:save'] schema_url = urls['url:schema'] -# To login we need to get CSRF token +# To login we need to get CSRF token from cookie token_url = urls['url:token'] -token = session.get(token_url).json()['data'] +# we need to trigger the creation of csrf token with this URL +session.get(token_url) +# but the token we want is accessed as a cookie +token = session.cookies.get_dict().get("csrftoken") print('CSRF token', token) # We add this to our session header # Needed for all POST, PUT, DELETE requests