D
D
dch742022-04-21 08:18:08
Python
dch74, 2022-04-21 08:18:08

POST request in python. I can't figure out what's wrong?

import json
import requests

url = 'https://app.mango-office.ru/vpbx/stats/request'
vpbx_api_key = 'ключ'
sign = 'подпись'
mango_json = {
    "date_from": "1072915200",
    "date_to": "1072997812",
    "fields": "records, start, finish, from_extension, from_number, to_extension, to_number, disconnect_reason", "call_party": {"extension": "116", "request_id": "001"}
}
data = {
    'key':  vpbx_api_key,
    'sign': sign,
    'json': json.dumps(mango_json),
}

req = requests.post(url, data=data)
print(req)


Response [401] arrives

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexBoss, 2022-04-21
@AlexBoss

I didn’t look much, but try sending the converted json to requests right away. That is, you collect a dictionary, and then pass json=data in the request

url = 'https://app.mango-office.ru/vpbx/stats/request'
vpbx_api_key = 'ключ'
sign = 'подпись'
mango_json = {
    "date_from": "1072915200",
    "date_to": "1072997812",
    "fields": "records, start, finish, from_extension, from_number, to_extension, to_number, disconnect_reason", "call_party": {"extension": "116", "request_id": "001"}
}
data = {
    'key':  vpbx_api_key,
    'sign': sign,
    'json': mango_json,
}

req = requests.post(url, json=data)
print(req)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question