欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

mysql的dbconn_管道错误使用mysql.conn

发布时间:2025/3/12 数据库 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 mysql的dbconn_管道错误使用mysql.conn 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我完全迷路了。这是我的管道。我说我跑错了File "c:\python27\lib\site-packages\twisted\internet\defer.py", line 588, in _runCallbacks

current.result = callback(current.result, *args, **kw)

File "C:\Python27\bff\bff\pipelines.py", line 42, in process_item

cursor.execute(add_Product)

File "c:\python27\lib\site-packages\mysql\connector\cursor.py", line 492, in execute

stmt = operation.encode(self._connection.python_charset)

AttributeError: 'tuple' object has no attribute 'encode'

正如您在注释代码中看到的,我尝试了几种不同的方法。一开始,正如我在示例中看到的那样做,但是我得到一个错误:当我把(item['StoreName'])放在值行中而不是在上面定义它为Name=item['StoreName']时,sadi item没有被定义

一、 我使用mySQL.connector我从mqsql.org网站网站。提前谢谢

^{pr2}$

编辑。这是我的新代码`

from __future__ import print_function

from datetime import date, datetime, timedelta

import mysql.connector

#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']

Model = item['ProdModel']

Desc = item['ProdDesc']

Price = item['ProdPrice']

Stock = item['InStock']

#Ships = item['Ships']

Name = item['StoreName']

cnx = mysql.connector.connect(user='****', password='****',

host='127.0.0.1',

port='****',

database='****')

cursor = cnx.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 "

"(ProdName, ProdPath, ProdUPC, ProdModel, ProdDesc, ProdPrice, InStock, StoreName) "

"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)")

#item['Ships'],

data_Product = (Product, Path, UPC, Model, Desc, Price, Stock, Name)

#Add new product

cursor.execute(add_Product, data_Product)

# Make sure data is committed to the database

cnx.commit()

cursor.close()

cnx.close()

return item

`

总结

以上是生活随笔为你收集整理的mysql的dbconn_管道错误使用mysql.conn的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。