Python 2.7, Magento Community 1.8 API连接问题


Python 2.7, Magento Community 1.8 API connection issues

我正在使用python-magento API进行连接,运气不佳。这个API正在尝试使用Magento的XML-RPC和连接到社区Magento 1.8…

我的本地安装是Python 2.7(64)在Windows 8上,而Magento在PHP 5.4堆栈上。

经过一些修改和使用了一些API后,这是python-magento API的主要错误,试图从Pycharm和DataNitro连接…

Traceback (most recent call last):
File "C:/Users/xxx/Documents/PYTHON/magento_test_connect.py", line 2, in <module>
magento = MagentoAPI("xxx.com", 80, "userxxx", "passxxx")
File "C:'Python27'lib'site-packages'magento'__init__.py", line 20, in __init__
self.login()
File "C:'Python27'lib'site-packages'magento'__init__.py", line 59, in login
self._session_id = self._client.login(self._api_user, self._api_key)
File "C:'Python27'lib'xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "C:'Python27'lib'xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "C:'Python27'lib'xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "C:'Python27'lib'xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "C:'Python27'lib'xmlrpclib.py", line 1473, in parse_response
return u.close()
File "C:'Python27'lib'xmlrpclib.py", line 793, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 2: 'Access denied.'>
Process finished with exit code 1

我一直在寻找一些方向,但现在我要扔一个赏金,因为我看到用Python连接Magento在网络上没有很好的文档。

我缩小到的代码是…

from magento import *
magento = MagentoAPI("xxx.com", 80, "userxxx", "passxxx")
magento.help() #just to see some results

转到直接url路径(检查防火墙问题),我得到…

<methodResponse><fault><value><struct><member><name>faultCode</name><value><int>630</int></value></member><member><name>faultString</name><value><string>Unable to read request</string></value></member></struct></value></fault></methodResponse>

我已经在Magento admin中输入了所有的详细信息,并给予了完整的权限。考虑过使用REST API,但在阅读了这个未回答的问题之后,看起来也有同样的问题。

* *

修改一下我的代码…

* *

import magento
url = 'xxx.com'
port = 8080
apiuser = 'userxxx'
apipass = 'passxxx'
with magento.MagentoAPI(url, port, apiuser, apipass) as product_api:
    order_filter = {'created_at':{'from':'2013-01-15 00:00:00'}}
    products = product_api.list(order_filter)

错误……

socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我可以在另一个Magento安装上设置这个,它工作了,显示…

Resources:
cart: create, info, license, order, totals
cart_coupon: add, remove
cart_customer: addresses, set
cart_payment: list, method
cart_product: add, list, moveToCustomerQuote, remove, update
cart_shipping: list, method
catalog_category: assignProduct, assignedProducts, create, currentStore, delete, info, level, move, removeProduct, tree, update, updateProduct
catalog_category_attribute: currentStore, list, options
catalog_product: create, currentStore, delete, getSpecialPrice, info, list, listOfAdditionalAttributes, setSpecialPrice, update
catalog_product_attribute: addOption, create, currentStore, info, list, options, remove, removeOption, types, update
catalog_product_attribute_media: create, currentStore, info, list, remove, types, update
catalog_product_attribute_set: attributeAdd, attributeRemove, create, groupAdd, groupRemove, groupRename, list, remove
catalog_product_attribute_tier_price: info, update
catalog_product_custom_option: add, info, list, remove, types, update
catalog_product_custom_option_value: add, info, list, remove, update
catalog_product_downloadable_link: add, list, remove
catalog_product_link: assign, attributes, list, remove, types, update
catalog_product_tag: add, info, list, remove, update
catalog_product_type: list
cataloginventory_stock_item: list, update
core_magento: info
core_store: info, list
customer: create, delete, info, list, update
customer_address: create, delete, info, list, update
customer_group: list
directory_country: list
directory_region: list
giftmessage: setForQuote, setForQuoteItem, setForQuoteProduct
sales_order: addComment, cancel, hold, info, list, unhold
sales_order_creditmemo: addComment, cancel, create, info, list
sales_order_invoice: addComment, cancel, capture, create, info, list, void
sales_order_shipment: addComment, addTrack, create, getCarriers, info, list, removeTrack, sendInfo
Process finished with exit code 0

经过多次测试后,1.7的安装可以正常工作,而1.8在相同的服务器和配置上仍然处于阻塞状态。唯一的结论是1.8还没有完成API的使用,这个问题(截至2013年6月23日)是1.8 Magento的一个错误。

不确定线程发起者是否仍然有问题,但我在Magento 1.8中遇到了python-magento和xmlrpc问题。

from magento import *
m = MagentoAPI('mag1', 80, 'user', 'pass')

失败

<ProtocolError for mag1:80/magento/api/xmlrpc: 404 Not Found>

python-magento的默认路径是/magento/api/xmlrpc。

将此更改为'/index.php/api/xmlrpc'对我有效:

m = MagentoAPI('mag1', 80, 'user', 'pass', path='/index.php/api/xmlrpc')

成功。

Magento 1.8中新的重写处理导致的问题。更多信息请看这里:访问。

时出现Magento API错误

希望对你有帮助。

Jerry。