我正在使用 Python API 创建具有 5 个变体的产品。我已经成功地在商店中创建了产品,没有任何问题。我遇到的问题是产品创建后,我没有收到 Shopify 的回复。因此,我从服务器的 API 收到了一个 HttpException。
我可以处理这个问题,但我需要能够创建产品并使用新创建产品的变体 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 对象和连接等。如果我忽略了什么,请告诉我。预先感谢您的任何帮助。
请您参考如下方法:
看起来这是由于 Google App Engine 强加了 python 默认情况下通常没有的 http 超时。
How to set timeout for urlfetch in Google App Engine?说明如何将默认超时设置为最大值 60 秒。
