小编Pei*_*sou的帖子

使用Python向API Prestashop发出POST请求

我可以通过列出和创建产品Prestashop API。我想在我的网站上自动化一点产品更新过程。

但是我在尝试使用图像创建新产品以及将图像上传到我通过Web服务创建的产品中尝试上传图像时遇到问题。

我的代码中没有看到任何错误,因此我想知道是否使用Prestashop API出错了。

我的代码:

def addNewImage(product_id):
   file = 'foto.png'
   fd = io.open(file, "rb")
   data = fd.read()
   r = requests.post(urlimg + product_id, data=data,auth=(key,""), headers={'Content-Type': 'multipart/form-data'})
   print(r.status_code)
   print(r.headers)
   print(r.content)

Prints:

500
{'Server': 'nginx', 'Date': 'Fri, 31 May 2019 09:18:27 GMT', 'Content-Type': 'text/xml;charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Access-Time': '1559294307', 'X-Powered-By': 'PrestaShop Webservice', 'PSWS-Version': '1.7.5.2', 'Execution-Time': '0.003', 'Set-Cookie': 'PrestaShop-30ff13c7718a401c862ad41ea4c0505f=def50200b7a8c608f3053d32136569a34c897c09cea1230b5f8a0aee977e6caac3e22bea39c63c30bfc955fe344d2cbabf640dc75039c63b33c88c5f33e6b01f2b282047bfb0e05c8f8eb7af08f2cc5b0c906d2060f92fea65f73ce063bf6d87bd8ac4d03d1f9fc0d7b6bf56b1eb152575ef559d95f89fc4f0090124630ae292633b4e08cfee38cee533eb8abe151a7d9c47ed84366a5dd0e241242b809300f84b9bb2; expires=Thu, 20-Jun-2019 09:18:27 GMT; Max-Age=1728000; path=/; domain=example.com; secure; HttpOnly', 'Vary': 'Authorization', 'MS-Author-Via': 'DAV'}

b'<?xml version="1.0" encoding="UTF-8"?>
\n<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
   \n<errors>
        \n<error>
            \n<code><![CDATA[66]]></code> …
Run Code Online (Sandbox Code Playgroud)

python web-services request prestashop-1.7

6
推荐指数
1
解决办法
222
查看次数

标签 统计

prestashop-1.7 ×1

python ×1

request ×1

web-services ×1