S
S
solovey12021-03-22 20:59:26
Python
solovey1, 2021-03-22 20:59:26

How to send json in POST request?

Hello!
Tell me, please, I need to send a POST request like this (example):

{
 "document": {
 "birthDate": "1989-11-19",
 "lastName": "Симонов",
 "firstName": "Владимир",
 "middleName": "Иванович"
 }


Wrote code like this:
import requests
import json
    name =input("Введите Фамилию:")
    surname =input("Введите Имя:")
    middlename  =input("Введите Отчество:")
    birthday =input("Введите дату рождения(ГГГГ-ММ-ДД):")

    url = '*******'  
    headers = {'token': '*************'}
    data = {"document": {
    "birthDate": birthday,
    "lastName": surname,
    "firstName": name,
    "middleName": middlename}
    }
    r = requests.post(url, headers=headers, json=data)


But when sending a request, for some reason instead of the Cyrillic alphabet in the request, the encoded text leaves.
Введите Фамилию:Симонов
Введите Имя:Владимир
Введите Отчество:Иванович
Введите дату рождения(ГГГГ-ММ-ДД):1989-11-19
Симонов Владимир Иванович 1989-11-19
b'{"document": {"birthDate": "1989-11-19", "lastName": "\\u0412\\u043b\\u0430\\u0434\\u0438\\u043c\\u0438\\u0440", "firstName": "\\u0421\\u0438\\u043c\\u043e\\u043d\\u043e\\u0432", "middleName": "\\u0418\\u0432\\u0430\\u043d\\u043e\\u0432\\u0438\\u0447"}}'

How can this problem be solved?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2021-03-22
@bacon

This is not a problem, everything is ok.

M
MinTnt, 2021-03-22
@MinTnt

Try not,
json = data ,
but simply,
data = data

O
o5a, 2021-03-23
@o5a

surname/lastname - last name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question