python-magento icon indicating copy to clipboard operation
python-magento copied to clipboard

Example code does not work

Open adamlwgriffiths opened this issue 8 years ago • 12 comments

Running the demo on the README with the latest Pypi release causes an error:

$ python test.py
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    products = client.product.list(order_filter)
AttributeError: 'API' object has no attribute 'product'

The API class does not have a product attribute.

adamlwgriffiths avatar Mar 21 '17 04:03 adamlwgriffiths

I am also having this issue, but running client.product_attribute_set.list()

AttributeError: 'API' object has no attribute 'product_attribute_set'

lilbumblebear avatar Apr 17 '17 20:04 lilbumblebear

It doesn't work on Python 3.5 and above, because api.py uses old method for declaring metaclass, see: https://stackoverflow.com/questions/39013249/metaclass-in-python3-5

Talv avatar Jun 08 '17 13:06 Talv

I'm getting the same error as @adamlwgriffiths . I'm also running python 2.7 so I don't think that @Talv comment applies to me. Has anyone found a solution?

hankmoody801 avatar Jul 10 '17 18:07 hankmoody801

I can get it to work on my local machine but it won't run on my server. I get the error: AttributeError: 'API' object has no attribute 'product'

On my local machine it returns the products as expected. Any idea?

hankmoody801 avatar Jul 10 '17 18:07 hankmoody801

SOLUTION: catalog.py, checkout.py, customer.py, and directory.py are inside the magento directory so edit each of these files like so...

Change: from magento.api import API To: from .api import API

Everything works great. Thanks.

hankmoody801 avatar Jul 10 '17 21:07 hankmoody801

The SOLUTION suggested by @hankmoody801 is not working at all. Actually, as @Talv said, the problem relates to the metaclass declaring in python3. You should add the metaclass as a parameter to API class: class API(object, metaclass = ClientApiMeta)

The previous metaclass assignments in Python3 are all ignored.

aLoneStrider avatar Sep 19 '17 20:09 aLoneStrider

@aLoneStrider...I made the change you suggested and I am still getting the same error. Any help would be much appreciated. Thanks in advance.

class API(object, metaclass = ClientApiMeta):
    """
    Generic API to connect to magento
    """
    
    #__metaclass__ = ClientApiMeta
    __abstract__ = True

    def __init__(self, url, username, password,
                 version='1.3.2.4', full_url=False,
                 protocol='xmlrpc', transport=None,
                 verify_ssl=True): ...

AttributeError: 'API' object has no attribute 'product'

beautifulDrifter avatar Oct 23 '17 21:10 beautifulDrifter

In line 60 of api.py I added ", metaclass = ClientApiMeta" (no need to add a comment with # in line 64) and the "AttributeError: 'API' object has no attribute 'product_attribute_set'" error has been solved.

I am running the script with Python 3.4.5, created in an Anaconda environment, Win10 OS, and Magento 1.9.3.7

Original code line 60 of api.py:

class API(object):

Final corrected code:

class API(object, metaclass = ClientApiMeta):

Thanks for the solution and thank you very much for the Magento Python API module!

jlgabriel avatar Mar 20 '18 18:03 jlgabriel

No solution provided here so far has helped me to get anything from the api. I ended up using the "Old way" and it seems to work fine.

josemarevalo avatar Aug 11 '18 10:08 josemarevalo

In line 60 of api.py I added ", metaclass = ClientApiMeta" (no need to add a comment with # in line 64) and the "AttributeError: 'API' object has no attribute 'product_attribute_set'" error has been solved.

I am running the script with Python 3.4.5, created in an Anaconda environment, Win10 OS, and Magento 1.9.3.7

Original code line 60 of api.py:

class API(object):

Final corrected code:

class API(object, metaclass = ClientApiMeta):

Thanks for the solution and thank you very much for the Magento Python API module!

I had the same problem originally, but this seemed to have solved the issue. I did a quick test and listed my products. On to do more testing!

Thanks to all of you that figured it out!

joegarcia avatar Sep 13 '18 16:09 joegarcia

catalog.py, checkout.py, customer.py, and directory.py are inside the magento directory so edit each of these files like so...

Change: from magento.api import API To: from .api import API After changing the import bellow error display mlrpclib.ProtocolError: <ProtocolError for Valid-IPaddress:port/index.php/api/xmlrpc: 404 Not Found>

prakashjain avatar Nov 19 '18 11:11 prakashjain

I need help I want to use this lib with my own odoo 12 module to connect to magento 2.3.4 is it possible !!

walidromdhani avatar Apr 08 '20 23:04 walidromdhani