python-magento
python-magento copied to clipboard
Example code does not work
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.
I am also having this issue, but running client.product_attribute_set.list()
AttributeError: 'API' object has no attribute 'product_attribute_set'
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
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?
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?
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.
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...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'
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!
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.
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!
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 APITo:from .api import APIAfter changing the import bellow error display mlrpclib.ProtocolError: <ProtocolError for Valid-IPaddress:port/index.php/api/xmlrpc: 404 Not Found>
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 !!