我正在嘗試創建一個腳本來通過Python將產品添加到prestashop。prestapyt無法上傳新產品
我正在使用prestapyt庫;我可以讀取文件,我可以獲取新文件的模板,但無法上傳新文件。這是我有:
from prestapyt import PrestaShopWebServiceError
from prestapyt import PrestaShopWebService
from prestapyt import PrestaShopWebServiceDict
DEBUG = 'true'
PS_SHOP_PATH = MYPATH
PS_WS_AUTH_KEY = MYKEY
prestashop = PrestaShopWebServiceDict(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG)
myproducts = prestashop.search('products');
addNewProduct(prestashop)
其中
def addNewProduct(prestashop):
blank_product = prestashop.get('products', options={'schema': 'blank'});
pprint(blank_product)
blank_product.update({'active': '1',
'additional_shipping_cost': '',
'advanced_stock_management': '',
'description': {'language': {'attrs': {'id': '2'}, 'value': 'DESCRIPTION!!!'}},
'description_short': {'language': {'attrs': {'id': '2'},
'value': 'SHORT DESCRIPTION!!!'}},
'id': '23',
'id_category_default': '2',
'name': {'language': {'attrs': {'id': '2'}, 'value': 'NAME'}},
'new': '1',
'price': '23',
'reference': 'MYREF',
'show_price': '1',
'width': ''})
prestashop.add('products', blank_product)
當運行這個紙條我得到如下:
Execute url: MYPATH/api/products/method: POST Response code: 400
Response headers:
{'status': '400', 'psws-version': '1.6.1.6', 'x-powered-by': 'PrestaShop Webservice', 'transfer-encoding': 'chunked', 'set-cookie': 'PrestaShop-a0d2999cb4d9d838ea9bbca3cf8a7a22=gv2rmNYce013aHwM2TQ7718d8sl%2BCmTtT1hO7pqS6ItiGKUPTa%2FGUwpTprJh9pihDKJbQNq4DKb0N6SYqC5nxBM4Q%2F1AFCrubceV8yPEcMo%3D000079; expires=Tue, 27-Sep-2016 21:15:16 GMT; Max-Age=1728000; path=MYPATH; domain=SOMETHING; httponly', 'access-time': '1473282916', 'connection': 'close', 'execution-time': '0.008', 'date': 'Wed, 07 Sep 2016 21:15:16 GMT', 'server': 'Apache', 'content-type': 'text/xml;charset=utf-8'}
Response body:
'PrestaShop error: 400 Bad Request. Internal error. To see this error please display the PHP errors.'
任何IDEIA?
謝謝!
更新: 我加了你的建議,這是我所得到的:
Traceback (most recent call last):
File "Script.py", line 24, in <module>
prestashop.edit('products', 1, address_data)
File "build/bdist.macosx-10.11-intel/egg/prestapyt/prestapyt.py", line 363, in edit
File "SAME", line 516,
in edit_with_url File "SAME", line 374,
in edit_with_url File "SAME", line 196,
in _execute File "SAME", line 127,
in _check_status_code
prestapyt.prestapyt.PrestaShopWebServiceError: 'PrestaShop error: 400 Bad Request. Internal error. To see this error please display the PHP errors.'
而且它打破了這裏:
address_data = prestashop.get('products', 1)
address_data['active'] = '0'
prestashop.edit('products', 1, address_data) -> THIS LINE
什麼新的想法?謝謝!
*看到這個錯誤,請顯示PHP錯誤*在配置/ defines.inc.php改變來定義(「_ PS_MODE_DEV_」,真)。 –
嘗試在PrestaShop後臺啓用「CGI模式」。改變像@SergiiP所說的定義。 – sarcom
等一下。我在我的筆記本電腦上運行這個,作爲一個Python腳本。不是一個PHP的東西。我還應該在服務器上這樣做嗎? – Carollour