gpt4 book ai didi

python - mysqldb编程错误

转载 作者:行者123 更新时间:2023-11-30 22:28:10 25 4
gpt4 key购买 nike

我在尝试使用 MySQLdb 插入表时遇到错误,但无法弄清楚。我查看了如何捕获错误,但是当我添加代码来捕获它时,当我尝试使用 raise e 而不是 print 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

最佳答案

我知道发生了什么。这实际上是两件事。其中有几个我将列设置为 varchar(200) 并且获得了超过 2400 个字符,因此增加它修复了这个问题。在我没有转义的 URL 上,这导致了错误。再次感谢。 – 尼克刚刚编辑

关于python - mysqldb编程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34666364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com