Skip to content

The SKU (xxxxxx) you are trying to insert is already under processing  #104

@relderdesigner

Description

@relderdesigner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy