在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ ProgrammingError: (1064, "You have

ProgrammingError: (1064, "You have an error in your SQL syntax

1.使用mysqldb庫(kù)1.2.5版本。在scrapy的pipeline文件中進(jìn)行插入數(shù)據(jù)庫(kù)操作時(shí),報(bào)錯(cuò)。
clipboard.png

2.這是報(bào)錯(cuò)的完整信息

clipboard.png

這是對(duì)應(yīng)的pipeline文件
import MySQLdb
import os.path

class ProjectPipeline(object):

def process_item(self, item, spider):
    name = item['name'].encode('utf8')
    location = item['location'].encode('utf8')
    describe = item['describe'].encode('utf8')    
    picture = item['picture'].encode('utf8')
    comment = item['comment'].encode('utf8')

    conn = MySQLdb.connect(
        host = 'localhost',
        port = 3306,
        user = 'root',
        passwd = '3285109',
        db = 'django',
        charset = 'utf8')
    cur = conn.cursor()
    cur.execute("INSERT INTO django_tmp(name,location,describe,picture,comment) values(%s,%s,%s,%s,%s)", (name,location,describe,picture,comment))
    cur.close()
    conn.commit()

    return item

再送上我的數(shù)據(jù)庫(kù)的表
clipboard.png

3.最可氣的就是我在其他的scrapy項(xiàng)目中成功的對(duì)數(shù)據(jù)庫(kù)成功地進(jìn)行了插入?。?!
這是代碼

import MySQLdb
import os.path

class WeatherPipeline(object):

def process_item(self, item, spider):
    cityDate = item['cityDate'].encode('utf8')
    week = item['week'].encode('utf8')
    img = os.path.basename(item['img'])
    temperature = item['temperature'].encode('utf8')
    weather = item['weather'].encode('utf8')
    wind = item['wind'].encode('utf8')
    conn = MySQLdb.connect(
        host = 'localhost',
        port = 3306,
        user = 'root',
        passwd = '3285109',
        db = 'scrapyDB',
        charset = 'utf8')
    cur = conn.cursor()
    cur.execute("INSERT INTO weather(cityDate,week,img,temperature,weather,wind) values(%s,%s,%s,%s,%s,%s)", (cityDate,week,img,temperature,weather,wind))
    cur.close()
    conn.commit()
    conn.close()

    return item

這是表的設(shè)計(jì)

clipboard.png

再來就是運(yùn)行成功的樣子

clipboard.png

clipboard.png

再到數(shù)據(jù)庫(kù)中查看一下!果然是有數(shù)據(jù)的

clipboard.png

4.那么問題來了?。?!為什么我檢查了很多遍也沒有發(fā)現(xiàn)到底兩者之間有什么不同,導(dǎo)致我的第一個(gè)文件語法錯(cuò)誤?。?!我是新手,在做畢業(yè)設(shè)計(jì),真心求大神不要嫌棄,給我指點(diǎn)一下!謝謝!

回答
編輯回答
來守候

。。。。。時(shí)隔這么長(zhǎng)的時(shí)間再上來看這個(gè)問題!!我搞懂了!??!
python所謂的格式字符串!?。?br>a = 'ztm'
print 'ab%scd'%a
則會(huì)輸出abztmcd
a = 'ztm'
b = 123
print 'ab%scd%de'%(a,b)
則會(huì)輸出abztmcd123de

2018年2月12日 00:15