Skip to content

Commit

Permalink
Merge pull request ome#6391 from will-moore/json_api_python_csrf_fix
Browse files Browse the repository at this point in the history
Use cookie to get csrf token in JSON API Login.py
  • Loading branch information
joshmoore committed Jun 13, 2024
2 parents dae4d1b + 7e8877d commit 88d0ec9
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 88d0ec9

Please sign in to comment.