我正在通過以下內容傳遞有效載荷字典。 有效載荷打印問題從亞馬遜的API上保存python上的MySql數據
('B01MTOV8IP', '35006', '23.95', '', 'now', 'Usually ships in 24 hours', 'https://www.amazon.com/reviews/iframe?akid=AKIAIDCPAFSAQICDTFNQ&alinkCode=xm2&asin=B01MTOV8IP&atag=reakenture-20&exp=2017-08-25T08%3A36%3A25Z&v=2&sig=QtRIZIBfjqq%252BPuYaUD%252BsoIxXSy2dRzYqCACDFm%252B%252BtV8%253D', 'CHG-GSTWL')
然後我得到這個錯誤:
我試圖改變的價值觀和STIP期間,我加STR(值),我也試過把它放在字典。我只需要將這些sku和他們的數據發送到數據庫。
當我變回%SI仍然得到這個錯誤 後來我得到這個錯誤:
文件「/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py」線36,在defaulterrorhandler 加註errorclass,errorvalue _mysql_exceptions.OperationalError:(1582年, 「不正確的參數計數在調用本地函數 'ISNULL'」) [成品在3.2S,退出代碼1]
I also tried
payload =(
asin,
bsr,
str(selling_price_v),
str(listing_price_v),
availability_type,
availability,
reviews,
sku)
我的目標是保存mysql數據庫中的非空值。
下面是數據類型
class BSR(models.Model):
ItemSKU = models.CharField(primary_key=True,max_length=200, blank=True)
list_price = models.DecimalField(max_digits=6, blank=True, decimal_places=2)
selling_price = models.DecimalField(max_digits=6, blank=True, decimal_places=2)
availability = models.CharField(max_length=200, blank=True)
Best_Sellers_Rank = models.IntegerField(max_length=200, blank=True)
AISN = models.CharField(max_length=200, blank=True)
class Meta:
ordering = ['ItemSKU']
verbose_name_plural = "BSR TEMP DATA"
def __str__(self):
return self.ItemSKU
CODE
for sku in set(SKUS):
payload = []
try:
time.sleep(2)
product = amazon.lookup(ItemId=sku, IdType="SKU",SearchIndex='All')
bsr = product.sales_rank
print bsr
except Exception as e:
bsr=''
print bsr
# try:
# fprice = product.formatted_price#.strip("$").strip(".")
# print fprice
# except Exception as e:
# fprice = "n/a"
# print fprice
# print e
try:
asin = product.asin#.strip(".")
print asin
except Exception as e:
asin = ""
print asin
try:
listing_price = product.listing_price
# print selling_price[0]#type
print listing_price[0]#price
listing_price_v = listing_price[0]
except Exception as e:
listing_price_v = ""
print listing_price_v
# try:
# price = product.price
# print price#type
# # print selling_price[1]#price
# except Exception as e:
# price = "n/a"
# print price
# print e
try:
reviews = product.reviews[1]
print reviews
except Exception as e:
reviews = ""
print reviews
try:
availability_type = product.availability_type
print availability_type
except Exception as e:
availability_type = ""
print availability_type
try:
availability = product.availability
# if
print availability
except Exception as e:
availability = ""
print availability
try:
selling_price = product.price_and_currency
selling_price_v = selling_price[0]#type
print selling_price_v
except Exception as e:
selling_price = ""
conn = MySQLdb.connect(host="serveraddress", user="un", passwd="pw", db="API")
payload =[
asin,
bsr,
str(selling_price_v).replace('.',''),
str(listing_price_v).replace('.',''),
availability_type,
availability,
reviews,
sku]
print payload
# conn = sqlite3.connect('skubsr.db')
c = conn.cursor(as_dict=True)
c.execute("""UPDATE webservice_bsr
SET
AISN = IsNull(@AISN, %s),
Best_Sellers_Rank = IsNull(@Best_Sellers_Rank, %s)
selling_price = IsNull(@selling_price, %s),
listing_price = IsNull(@listing_price, %s),
availability_type = IsNull(@availability_type, %s),
availability = IsNull(@availability, %s),
reviews = IsNull(@reviews, %s)
WHERE ItemSKU = %s""", payload)
conn.commit()