import requests token = '' url_x_csrftoken = 'http://127.0.0.1:8000/api/get_xcsrf/' response = requests.get(url_x_csrftoken) x_csrftoken = response.json().get('X-CSRFToken') cookies = response.cookies cookies_dict = cookies.get_dict() csrftoken = cookies_dict.get('csrftoken') url = 'http://127.0.0.1:8000/api/users/' headers = { 'Authorization': f'Bearer {token}', 'X-CSRFToken': x_csrftoken, 'Cookie': f'csrftoken={csrftoken}' } data = { "lastname": "Qweqov", "firstname": "Petr", "middlename": "Qweyekovich", "username": "PetrQweqov", "password": "PetrQweqov@yandex.ru", "email": "PetrQweqov@yandex.ru", "phone": "89009401234", } response = requests.post(url, headers=headers, data=data) print(response.status_code) print(response.content) print(response.json())