Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code does not work #15

Open
adamlwgriffiths opened this issue Mar 21, 2017 · 12 comments
Open

Example code does not work #15

adamlwgriffiths opened this issue Mar 21, 2017 · 12 comments

Comments

@adamlwgriffiths
Copy link

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.

@lilbumblebear
Copy link

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

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

@Talv
Copy link

Talv commented Jun 8, 2017

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

@hankmoody801
Copy link

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
Copy link

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
Copy link

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.

@aLoneStrider
Copy link

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.

@beautifulDrifter
Copy link

@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'

@jlgabriel
Copy link

jlgabriel commented Mar 20, 2018

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!

@josemarevalo
Copy link

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.

@joegarcia
Copy link

joegarcia commented Sep 13, 2018

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!

@prakashjain
Copy link

prakashjain commented Nov 19, 2018

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>

@walidromdhani
Copy link

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 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests