J
J
Just_Bruh2020-06-10 09:03:26
Python
Just_Bruh, 2020-06-10 09:03:26

How to solve woocommerce API product creation error?

I'm trying to create a product according to the documentation:

from woocommerce import API

wcapi = API(
    url="http://...",
    consumer_key="ck_...",
    consumer_secret="cs_...",
    version="wc/v3"
)

data = {
    "name": "Товар 1",
    "type": "simple",
    "regular_price": "777",
    "description": "Мое описание",
    "short_description": "Короткое описание",
    "images": [
        {
            "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
        }
    ]
}

print(wcapi.post("products", data).json())

Answer:
Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/API/test.py", line 34, in <module>
    print(wcapi.post("products", data).json())
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question