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

`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值