woocommerce / woocommerce/wc-api-python
The SKU (xxxxxx) you are trying to insert is already under processing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 216
- Forks
- 108
- Avg merge
- 6h 34m
- Merged PRs (30d)
- 1
Description
Hi guys, I have a problem to create new product when import csv file, receive this erros e in log to woocommerce.
{
"error": "woocommerce_rest_product_not_created",
"code": 400
}
my code
import time
import threading
import pandas as pd
from woocommerce import API
wcapi = API(
url="https://xxxx",
consumer_key="AAA",
consumer_secret="AAA",
wp_api=True,
timeout=60,
version="wc/v3"
)
df = pd.read_csv("_@@_teste1produto.csv")
for index, row in df.iterrows():
data = {
'name': row['name'],
'type': row['type'],
'sku': str(row['isbn']),
'regular_price': str(row['price']),
'description': row['description'],
'categories': [{'name': row['categories']}],
'images': [{'src': row['image']}],
'status': row['status'],
'catalog_visibility': row['visibility'],
'tax_status': row['tax_status'],
'weight': str(row['weight']),
'dimensions': {
'length': str(row['length']),
'width': str(row['width']),
'height': str(row['height'])
},
'manage_stock': True,
'stock_quantity': int(row['stock']),
}
product_lock = threading.Lock()
def create_or_update_product(wcapi, row, data):
max_retries = 3
retry_delay = 5
with product_lock:
for attempt in range(max_retries):
produtos_existentes = wcapi.get("products", params={'sku': row['isbn']}).json()
if produtos_existentes and isinstance(produtos_existentes, list) and len(produtos_existentes) > 0:
produto_id = produtos_existentes[0]['id']
resultado_atualizacao = wcapi.put(f"products/{produto_id}", data).json()
if 'id' in resultado_atualizacao:
print(f"Produto {row['name']} atualizado com sucesso! ID: {resultado_atualizacao['id']}")
return
else:
print(f"Erro ao atualizar o produto {row['name']}: {resultado_atualizacao}")
if attempt < max_retries - 1:
print(f"Tentando novamente em {retry_delay} segundos...")
time.sleep(retry_delay)
else:
resultado_criacao = wcapi.post("products", data).json()
if 'id' in resultado_criacao:
print(f"Produto {row['name']} criado com sucesso! ID: {resultado_criacao['id']}")
return
elif resultado_criacao.get('code') == 'woocommerce_rest_product_not_created' and 'already under processing' in resultado_criacao.get('message', ''):
print(f"Produto {row['name']} está sendo processado. Tentando novamente em {retry_delay} segundos...")
time.sleep(retry_delay)
else:
print(f"Erro ao criar o produto {row['name']}: {resultado_criacao}")
return
if row['isbn']:
create_or_update_product(wcapi, row, data)
someone can I help me? please.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start at the shown wcapi.get, wcapi.put, and wcapi.post calls for the products endpoint and reproduce the WooCommerce response with the CSV row; done would require a confirmed repository-scoped change and a test, neither of which this report specifies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100