Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cookie to get csrf token in JSON API Login.py #6391

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading