K
K
Kwad2020-05-22 17:24:21
Python
Kwad, 2020-05-22 17:24:21

Why is it giving a 400 requests python (api) error?

Hello, I'm writing a simple script and I can't figure out how to work with api json.
API:
5ec7e00eebf2c477705702.png
Code:

params = {
        "number_of_cycles": 1,
        "phone": "+38xxxxxxxxxx" # свой номер скрыл,и ошибки тут не должно быть
    }
    print(params)
    print(requests.post("http://127.0.0.1:9000/attack/start", data=params))

Error on the service side:
log

ERROR: Error getting request body: Expecting value: line 1 column 1 (char 0)
ERROR: Error getting request body: Expecting value: line 1 column 1 (char 0)
ERROR: Error getting request body: Expecting value: line 1 column 1 (char 0)
ERROR: Error getting request body: Expecting value: line 1 column 1 (char 0)

Where exactly is the error and how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2020-05-22
@Kwad

requests.post("http://127.0.0.1:9000/attack/start", data=json.dumps(params))
# или с версии 2.4.2
requests.post("http://127.0.0.1:9000/attack/start", json=params)

B
bubaley, 2020-05-22
@bubaley

Convert params to json string first
result = requests.post(" 127.0.0.1:9000/attack/start ", data=json.dumps(params))
print (result.json)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question