[Python] 400 error in API post request(python, requests). How to set correct parameters?

Discussão em 'Python' iniciado por Stack, Janeiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to load a list of leftovers using the Wildberries marketplace API using Python 3.10.


    import requests
    url = 'https://suppliers-api.wildberries.ru/api/v3/stocks/{warehouse}'
    key = 'my_key'
    headers_auth = {'Authorization': key}
    wh_id = my_id #int
    auth = requests.post(url.format(warehouse = wh_id), headers = headers_auth)
    print(auth)
    leftovers = auth.json()
    print(leftovers)



    I am getting the following message: <Response [400]> {'code': 'IncorrectRequestBody', 'message': 'Некорректное тело запроса'} Message translation is 'incorrect request body'

    What did I do wrong?

    You can see it in docs, but i'll point it here. There are no query parameters. 'warehouse' is only required path parameter. There are also mentioned REQUEST BODY SCHEMA, but not pointed it's 'required' to send some extra data.

    Documentation is here: https://openapi.wb.ru/#tag/Marketplace-Ostatki/paths/~1api~1v3~1stocks~1%7Bwarehouse%7D/post

    I also tried: 1)to write wh_id in path:

    url = 'https://suppliers-api.wildberries.ru/api/v3/stocks/wh_id
    auth = requests.post(url, headers = headers_auth)


    2)send warehouse in data, changing with different variants of url:

    data = {'warehouse':wh_id}
    auth = requests.post(url, data = data, headers = headers_auth)


    3)send array of barcodes like in REQUEST BODY SCHEMA

    barcodes = ['barcode']
    data = {"skus": barcodes}
    auth = requests.post(url.format(warehouse = wh_id), data=data, headers = headers_auth)


    At first i am expecting the 200 response code.

    Continue reading...

Compartilhe esta Página