G
G
Gnifajio2022-03-19 19:10:09
Python
Gnifajio, 2022-03-19 19:10:09

QIWI API error 400?

I'm trying to issue an invoice using the QIWI API. Everything seems to be licked from the documentation .
So far, I am limited to creating a form for 1p.
My code:

import requests
import json
import uuid



def test():
    payment_id = uuid.uuid4()
    secret_qiwi_key = 'eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6InpmemZ6Zi05OSIsInVzZXJfaWQiOiIrNzkxMjM0NTY3ODkiLCJzZWNyZXQiOiJ3fnBTQC1me2Fvbjd8Vmo4SnI1KXk/bURGRDRQZH5zODtTUU9aU3RSRFAwVXYrR2RTXTtyNWgqMj1zdilJZ08yIn19'
    url = f'https://api.qiwi.com/partner/bill/v1/bills/{payment_id}'
    headers = {
        'content-type': 'application/json',
        'accept': 'application/json',
        'authorization': f'Bearer {secret_qiwi_key}'
    }

    data = {
        'amount':{
            'currency': 'RUB',
            'value': '1.00'
        },
         "expirationDateTime": "2029-11-11T24:59:59+03:00",
    }
    resp = requests.put(url=url, data=data, headers=headers)
    
    return resp, payment_id

q = test()

print(f' [{q[0].ok} {q[0].status_code}] {q[0].content}')


Output:
[False 400] b'{"serviceName":"invoicing-api","errorCode":"http.message.conversion.failed","description":"Bad request","userMessage":"Bad request" ,"dateTime":"2022-03-19T18:51:52.926+03:00","traceId":"ffeeddbb33cc11cc"}'

Please don't link to the documentation, I read it anyway.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-03-19
@gnifajio

Don't pass Content-Type, requests can generate it by itself.

resp = requests.put(url=url, json=data, headers=headers)

Because the content type is application/json, the data must be passed to the parameter json, we remove the content type from the headers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question