Skip to content

Commit

Permalink
Use cookie to get csrf token in JSON API Login.py
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jun 10, 2024
1 parent dae4d1b commit 7e8877d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/Training/python/Json_Api/Login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e8877d

Please sign in to comment.