Я получаю ошибку "Response 500" когда пытаюсь добавить 5000 variable товаров и 1480 простых товарпов по Python Woocommerce Rest API. Я думаю, это из-за request timed out, но не знаю как исправить
К тому же, сервер ругается на таким образом:
[14-Sep-2022 23:18:00 UTC] PHP Warning: preg_match() expects parameter 2 to be string, array given in /home2/XXXXX/XXXXXX/wp-includes/class-wp-block-parser.php on line 417
[14-Sep-2022 23:18:00 UTC] PHP Warning: strlen() expects parameter 1 to be string, array given in /home2/XXXXX/XXXXXX/wp-includes/class-wp-block-parser.php on line 489
product__batch_create_simple = []
product__batch_update_simple = []
df = pandas.read_csv("toimport1.csv")
df['C'] = np.arange(len(df))
df.reset_index()
df = df.drop(df.columns[0], axis=1)
df = df.to_json(orient ='index')
loaded = json.loads(df)
def slugify(text):
text = unidecode.unidecode(text).lower()
return re.sub(r'[\W_]+', '-', text)
for iterator in loaded:
brands_array = str(loaded[iterator]["34"]).split(",")
cats = str(loaded[iterator]["33"]).split(",")
short_desc_ = []
images_ = []
desc_ = []
short_desc = []
images = []
desc = []
# try:
# sku=str(loaded[iterator]["1"])
# productlist=wcapi.get("products", params={'sku':sku}).json()
# productid=productlist[0].get("id")
# short_desc_ = productlist[0].get("short_description")
# images_ = productlist[0].get("images")
# desc_ = productlist[0].get("description")
# except:
# short_desc_ = []
# images_ = []
# desc_ = []
if short_desc_ is None:
pass
else:
short_desc = short_desc_
if images_ is None:
pass
else:
images = images_
if desc_ is None:
pass
else:
desc = desc_
product_data = {
"name": str(loaded[iterator]["2"]),
'slug': str(slugify(loaded[iterator]["2"])),
'permalink': str(slugify(loaded[iterator]["2"])),
'date_created': '2022-01-01T10:10:10',
'date_created_gmt': '2022-01-01T10:10:10',
'type': str(loaded[iterator]["0"]),
'sku': str(loaded[iterator]["1"]),
"regular_price": str(loaded[iterator]["14"]).replace(',','.'),
'sale_price': str(loaded[iterator]["15"]).replace(',','.'),
'purchasable': True,
'virtual': False,
'downloadable': False,
'downloads': [],
'tax_status': 'taxable',
'tax_class': '',
'manage_stock': True,
"stock_quantity": loaded[iterator]["8"],
'weight': str(loaded[iterator]["11"]).replace('.',','),
'dimensions': {
'length': str(loaded[iterator]["12"]).replace('.',','),
'width': str(loaded[iterator]["12"]).replace('.',','),
'height': str(loaded[iterator]["13"]).replace('.',',')
},
'shipping_required': True,
'shipping_taxable': True,
'shipping_class': '',
'shipping_class_id': 0,
'purchase_note': '',
'categories': [
{
'id': cats[0],
},
{
'id': cats[1],
},
{
'id': cats[2],
},
{
'id': brands_array[0],
},
{
'id': brands_array[1],
},
{
'id': brands_array[2],
},
],
'short_description': short_desc,
'images': images,
'description': desc,
'tags': [],
'attributes': [
{'id': 9, 'name': 'Brändi', 'position': 0, 'visible': True, 'variation': False, 'options': [str(loaded[iterator]["26"]).replace("None","")]},
{'id': 8, 'name': 'Väri', 'position': 1, 'visible': True, 'variation': True, 'options': [str(loaded[iterator]["19"]).replace("None","")]},
{'id': 6, 'name': 'Koko', 'position': 2, 'visible': True, 'variation': True, 'options': [str(loaded[iterator]["28"]).replace("None","")]},
],
'grouped_products': [],
'menu_order': 0,
'related_ids': [],
"meta_data": [
{"id": 1,
"key": "_pointss",
"value": loaded[iterator]["31"]
},
{"id": 2,
"key": "_m_cat_type",
"value": loaded[iterator]["32"]
},
{
"id": 3,
"key": "_text_field",
"value": loaded[iterator]["3"]
},
],
}
product__batch_create_simple.append(product_data)
#print(sku)
# try:
# sku=str(loaded[iterator]["1"])
# productlist=wcapi.get("products", params={'sku':sku}).json()
# productid=productlist[0].get("id")
# product__batch_update_simple.append(product_data)
# print(sku)
# except Exception as e:
# product__batch_create_simple.append(product_data)
# print(sku)
product__batch_data = {
"create": product__batch_create_simple,
"update": product__batch_update_simple
}
response = wcapi.post("products/batch", product__batch_data)
print(response)