私はペイロード辞書に次のものを渡しています。 ペイロードプリントAmazonの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')
そして私はこのエラーを取得する:
Iの値を変更し、期間をSTIPしようと、私はSTR(価値)を添加し、私はまた、辞書でそれを置くことを試みました。私はちょうどそれらのSKUとそのデータをデータベースに送る必要があります。
私はまだ、このエラー を取得するバック%のSiと変更その後、私はこのエラーを取得する:
ファイル「/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py」、 defaulterrorhandler 上げerrorclass、errorvalue _mysql_exceptions.OperationalErrorの行36、[終了コード1と3.2Sに仕上げ](1582年、 "ネイティブ関数への呼び出しで誤ったパラメータ数 'のIsNull'")
I also tried
payload =(
asin,
bsr,
str(selling_price_v),
str(listing_price_v),
availability_type,
availability,
reviews,
sku)
私の目標は、nullでない値をmysqlデータベースに保存することです。ここで
は、私はあなたが機能isnull
を誤解推測
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()