我在尝试使用MySQLdb插入表时遇到错误,无法弄明白。我查找了如何捕获错误,但是当我添加代码来捕获它时,当我尝试使用raise e而不是print e时,我没有得到任何其他信息,当我尝试打印时,我得到一个错误。我需要一些帮助来获取错误以给我更多细节。我会包含整个代码,万一有人非常棒,看看我哪里出错了。然后我甚至不关心错误捕获。好的,我是的,因为我相信我很快就会再次需要它。大声笑。我实际上有8列需要更新。我正在尝试使用消除过程,一次只尝试一对。像UPC,Name和其他几个插入很好,但Modl,Path和Desc导致错误。任何帮助都将受到赞赏和感谢。
# -*- coding: utf-8 -*-
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from __future__ import print_function
from datetime import date, datetime, timedelta
import MySQLdb
#from scrapy.extensions import DropItem
#from bff.items import ItemInfo
class mySQLPipeline(object):
def process_item(self, item, spider):
Product = item['ProdName']
Path = item['ProdPath']
UPC = item['ProdUPC']
Modl = item['ProdModel']
Desc = item['ProdDesc']
Price = item['ProdPrice']
Stock = item['InStock']
#Ships = item['Ships']
Name = item['StoreName']
#Not Failing during insert Product, Price, Stock, Name
#FAILing during insert Modl, Path, Desc,
db = MySQLdb.connect(user='****', passwd='****',
host='127.0.0.1',
port=****,
db='****')
cursor = db.cursor()
# add_Product = ("INSERT INTO walmart_products (ProdName, StoreName) VALUES (%s, %s,)", Product, Name,)
# add_Product = ("INSERT INTO walmart_products, (ProdName)"
# "VALUES (%s)", (Name))
# "VALUES (%(Name)s)")
add_Product = ("INSERT INTO walmart_products "
"(InStock, StoreName) "
"VALUES (%s, %s)")
#item['Ships'],
data_Product = (Stock, Name)
#Add new product
#try:
cursor.execute(add_Product, data_Product)
#except MySQLdb.IntegrityError, e:
#print e
# handle a specific error condition
#except MySQLdb.Error, e:
#raise e
# handle a generic error condition
#except MySQLdb.Warning, e:
#print e
# handle warnings, if the cursor you're using raises them
#except MySQLdb.ProgrammingError, e:
#print e
# Make sure data is committed to the database
db.commit()
cursor.close()
db.close()
return item
答案 0 :(得分:0)
我弄清楚发生了什么。这实际上是一些事情。其中一个我将列设置为varchar(200)并且已经超过2400个字符,因此增加它固定了它。在我的URL上没有逃避它,这导致了错误。再次感谢。 - 尼克刚刚编辑