【发布时间】:2012-12-22 05:58:34
【问题描述】:
我正在使用 Python API 创建具有 5 个变体的产品。我已经成功地在商店中创建了产品,没有问题。我遇到的问题是产品创建后,我没有收到 Shopify 的回复。因此,我从服务器中的 API 收到 HttpException。
我可以处理这个问题,但我需要能够创建产品并使用新创建的产品的 Variant ID 填充表单。我试图通过 Ajax 调用来发起对 Shopify 的服务器调用,但我也尝试了对服务器的同步请求,但我仍然没有收到 Shopify 的响应。
产品详情如下:
custom_product = shopify.Product()
custom_product.product_type = 'Custom Shirt'
custom_product.body_html = '<strong>Custom Shirt</strong>'
custom_product.title = 'Custom Shirt'
variant1 = shopify.Variant(dict(price=0, option1='Small'))
variant2 = shopify.Variant(dict(price=0, option1='Medium'))
variant3 = shopify.Variant(dict(price=0, option1='Large'))
variant4 = shopify.Variant(dict(price=0, option1='Extra Large'))
variant5 = shopify.Variant(dict(price=0, option1='2XL'))
variant6 = shopify.Variant(dict(price=price, option1='Bundle'))
custom_product.variants = [variant1,variant2,variant3,variant4,variant5, variant6]
# create images for front and back
front_image = shopify.Image(attributes=dict(shot='front'))
front_id = front_shirt_model.key().id()
front_image.src = 'http://myurl.com/img/'+str(front_id)
back_image = shopify.Image(attributes=dict(shot='back'))
back_id = back_shirt_model.key().id()
back_image.src = 'http://myurl.com/img/'+str(back_id)
custom_product.images = [front_image, back_image]
success = custom_product.save()
我还应该提到我在 Google App Engine 上使用 Django。我尝试了不同的替代方法,例如使用 requests Python 库来创建请求 JSON 对象和连接等。如果有什么我忽略了,请告诉我。预先感谢您的任何帮助。
【问题讨论】:
-
异常类和消息是什么?是否所有请求都失败(例如 shopify.Shop.current() 是否失败),是否有任何产品创建请求(例如,使用 title、product_type 和 body_html 创建产品)或产品数据的这种特定组合?能否提供请求
shopify.Product.connection.response.headers['x-request-id']的请求ID? -
这是一个 HttpTimeout 异常。异常类来自 Python Shopify API,因为它没有收到来自 save() 方法的响应和对商店的请求。就此而言,我收到了商店中所有产品的回复,以及我尝试过的所有其他请求。它必须与 Google App Engine 或我的请求从前端链接的方式有关。当我使用 Python 解释器时,我可以使用与我个人机器上的应用程序中完全相同的代码,并且我可以正确接收所有内容。
-
我想我必须注意,我在大约 100 次尝试中收到了 1 次响应。那时我能够获得创建的产品 ID。
标签: python django api google-app-engine shopify