2

I am using the Python API to create a Product with 5 Variants. I have been successful in creating the product in the store, without issue. The problem I have is once the product is created, I do not receive a response from Shopify. Because of this, I receive an HttpException from the API in my server.

I can deal with this, but I need to be able to create the product and populate a form with the Variant IDs of the newly created product. I was attempting this via an Ajax call to initiate the server call to Shopify, but I have also tried a synchronous request to the server, and I still do not receive a response from Shopify.

The Product details are as follows:

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()

I should also mention that I am using Django on Google App Engine. I have tried different alternatives such as using the requests Python library to create the request JSON objects and connections, among others. Please let me know if there is something I have overlooked. Thank you in advance for any help.

zachhilbert
  • 639
  • 1
  • 5
  • 12
  • What is the exception class and message? Do all requests fail (e.g. does shopify.Shop.current() fail), any product creation request (e.g. create product with title, product_type and body_html) or this specific combination of product data? Could you provide the request ID for the request `shopify.Product.connection.response.headers['x-request-id']`? – Dylan Smith Dec 23 '12 at 09:45
  • It is an HttpTimeout exception. The exception class comes from the Python Shopify API because it doesn't receive a response from the save() method and request to the store. I receive a response for all products in the store, and all other requests I've tried, for that matter. It has to be something either with Google App Engine or the way my request is chained from the front end. When I use the Python interpretor, I can use the same exact code, as in my application from my personal machine, and I receive everything correctly. – zachhilbert Dec 23 '12 at 15:49
  • I guess I must note, I have received a response 1 time in about 100 attempts. At that point I was able to get the created product id. – zachhilbert Dec 23 '12 at 16:02

1 Answers1

0

It looks like this is due to the Google App Engine imposing a http timeout which python normally doesn't have by default.

How to set timeout for urlfetch in Google App Engine? explains how to set the default timeout to the maximum of 60 seconds.

Community
  • 1
  • 1
Dylan Smith
  • 1,502
  • 8
  • 9
  • This seemed to have worked just fine. I thought at first it didn't, but once I pushed to App Engine, I was able to get the request ID and other product information I need. It seems like such a commonsense fix, but it has been a long time working on it. Thank you for your help. – zachhilbert Dec 23 '12 at 20:09