def add_images(self, product_ids, images):
domain = self.shop.domain
headers = {'Content-Type': MULTIPART_CONTENT,
'Authorization': self.shop.authheader}
for i, p_images in enumerate(images):
# TODO: why sometimes index does not exist?
if i >= len(product_ids):
send_email.delay('mail/error', {'domain': domain, 'message': str(product_ids),
'data_list': '',
'full_data': ''}, "Add images error")
break
product_id = product_ids[i]
for image in p_images:
data = encode_multipart(BOUNDARY, {'image': image})
req = urllib2.Request(smart_str("http://%s/api/images/products/%s" % (domain, product_id)),
headers=headers, data=smart_str(data))
urllib2.urlopen(req)
self.make_first_image_default(product_ids, headers)
评论列表
文章目录