2012-12-22 46 views
2

我正在使用Python API來創建包含5個變體的產品。我已經成功地在商店中創建產品,沒有問題。我擁有的問題是一旦產品被創建,我沒有收到Shopify的迴應。因此,我從服務器中的API接收到HttpException。使用Python API創建產品時未收到Shopify的響應

我可以處理這個問題,但我需要能夠創建產品並用新創建的產品的變體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() 

我還要提到的是我在谷歌App Engine的使用Django。我嘗試了不同的選擇,例如使用請求Python庫創建請求JSON對象和連接等。請讓我知道是否有一些我忽視的東西。預先感謝您的任何幫助。

+0

什麼是異常類和消息?所有請求都失敗(例如shopify.Shop.current()失敗),任何產品創建請求(例如創建帶有標題,product_type和body_html的產品)還是產品數據的特定組合?您能否提供請求的請求ID「shopify.Product.connection.response.headers ['x-request-id']'? –

+0

這是一個HttpTimeout異常。異常類來自Python Shopify API,因爲它沒有收到save()方法和對商店的請求的響應。我收到了商店中所有產品的回覆,以及我嘗試過的所有其他請求。它必須是Google App Engine或我的請求與前端鏈接的方式。當我使用Python解釋器時,我可以使用與我的個人機器上的應用程序相同的確切代碼,並且我可以正確接收所有內容。 – zachhilbert

+0

我想我必須注意到,我在100次嘗試中收到了1次迴應。那時我能夠獲得創建的產品ID。 – zachhilbert

回答

0

看起來這是由於谷歌應用引擎強加一個http默認情況下python通常沒有的超時。

How to set timeout for urlfetch in Google App Engine?說明如何將默認超時設置爲最大60秒。

+0

這似乎工作得很好。我一開始認爲它沒有,但是一旦我推到App Engine,我就可以獲得我需要的請求ID和其他產品信息。這似乎是一個常見的問題,但它已經很長時間了。感謝您的幫助。 – zachhilbert

相關問題