psychomantis101's avatar

Getting CSRF on external source (using python)

I am attempting to post data from an external source and have actually succeeded but only by making an CSRF exception to the URL in question. My attempts to make it work while keeping CSRF active have failed. I attempt to get a CSRF token from the XSRF-TOKEN cookie, however I notice it's a much longer number than the CSRF token you normally get from forms when doing

{{ csrf_field() }}

Anyway, here is what I attempted (Using python)

import requests
with requests.Session() as c:
    url = "https//example.com/test"
    foo = 1
    bar = "hello"

    c.get(url)

    csrftoken = c.cookies['XSRF-TOKEN']

    main_data = dict(_token=csrftoken, foo_id=foo, bar_message=bar)
    c.post(url, data=main_data, headers = {"Referer": "https://example.com"})
0 likes
0 replies

Please or to participate in this conversation.