【问题标题】:Not Receiving a Response from Shopify When Creating a Product Using Python API使用 Python API 创建产品时未收到 Shopify 的响应
【发布时间】: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


【解决方案1】:

看起来这是由于 Google App Engine 施加了一个 http 超时,而 python 通常默认情况下没有。

How to set timeout for urlfetch in Google App Engine? 解释了如何将默认超时设置为最长 60 秒。

【讨论】:

  • 这似乎工作得很好。起初我以为没有,但是一旦我推送到 App Engine,我就能够获得我需要的请求 ID 和其他产品信息。这似乎是一个常识性的修复,但它已经很长时间了。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2015-04-04
  • 2012-06-11
  • 2016-05-31
  • 2020-06-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
  • 1970-01-01
相关资源
最近更新 更多