@DanielWorker
Junior Python Developer

Как перевести POST запрос с PHP на Python?

Мне нужно сделать POST запрос на Python, но пример запроса есть только в php, может кто помочь перевести?
PHP:
<?php
$url = 'https://joinposter.com/api/storage.createSupply'
    . '?token=687409:4164553abf6a031302898da7800b59fb';

$supply = [
    "supply" => [
        "date"          => date("Y-m-d H:i:s"),
        "supplier_id"   => "1",
        "storage_id"    => "1",
        "packing"       => "1"
    ],
    "ingredient" => [
        [
            "id"        => "138",
            "type"      => "1",
            "num"       => "3",
            "sum"       => "6",
        ]
    ]
];

$data = sendRequest($url, 'post', $supply);


Моя попытка на Python:
url = 'https://apidemo.joinposter.com/api/storage.createSupply?token=' + token

data = {
        'supply': {
            'date': datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S'),
            'supplier_id': supplier_id,
            'storage_id': '1'
        },
        'ingredient': {
            'id': item_id,
            'type': item_type,
            'num': amount,
            'sum': local_sum
        }
    }

response = requests.post(url, data=data)
  • Вопрос задан
  • 111 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы