Answer the question
In order to leave comments, you need to log in
How to translate POST request from PHP to Python?
I need to make a POST request in Python, but the request example is only in php, can anyone help translate?
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);
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)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question