gpt4 book ai didi

python api-shopify.Variant 404 错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:32 27 4
gpt4 key购买 nike

尝试使用 python 库创建一个新的变体。

创建 shopify session 后,我只是尝试根据文档创建一个 Variant 实例

session = shopify.Session('<My Url>')
session.token = self.provider_access_token
shopify.ShopifyResource.activate_session(session)

v=shopify.Variant(dict(price="20.00", option1="Second"))
v.save()

并得到:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/yoda/.virtualenvs/myproject/src/shopify/shopify/base.py", line 151, in save
return super(ShopifyResource, self).save()
File "/Users/yoda/.virtualenvs/myproject/lib/python2.6/site-packages/pyactiveresource /activeresource.py", line 732, in save
data=self.to_xml())
File "/Users/yoda/.virtualenvs/myproject/lib/python2.6/site-packages/pyactiveresource /connection.py", line 313, in post
return self._open('POST', path, headers=headers, data=data)
File "/Users/yoda/.virtualenvs/myproject/src/shopify/shopify/base.py", line 18, in _open
self.response = super(ShopifyConnection, self)._open(*args, **kwargs)
File "/Users/yoda/.virtualenvs/myproject/lib/python2.6/site-packages/pyactiveresource /connection.py", line 258, in _open
response = Response.from_httpresponse(self._handle_error(err))
File "/Users/yoda/.virtualenvs/myproject/lib/python2.6/site-packages/pyactiveresource /connection.py", line 357, in _handle_error
raise ResourceNotFound(err)
ResourceNotFound: HTTP Error 404: Not Found

有什么想法或提示吗? :)

谢谢RCdH

最佳答案

在列出、计数或创建操作时,产品变体必须指定一个 product_id。这可以在 Product Variant API docs 中看到因为 product_id 是 URL 路径的一部分。正是由于这个原因,Shopify 返回了 404 错误,因为路径不存在。

using the shopify_python_api Shopify Wiki 上的页面有一个关于前缀选项的部分,您可能会发现它很有用。

在您的示例中,您只需要更改行

v=shopify.Variant(dict(price="20.00", option1="Second"))

v=shopify.Variant(dict(price="20.00", option1="Second", product_id=product.id))

假设您有一个产品要在变量 product 中创建变体。

关于python api-shopify.Variant 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11069881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com