(博彩导航网) Python pymysql写入数据库报错
在线博彩导航
在线博彩导航
当前位置 : 在线博彩导航 > 博彩导航网

(博彩导航网) Python pymysql写入数据库报错

我在用Python pymysql写入数据库时一直报错:
pymysql.err.InternalError: 1366, u"Incorrect decimal value: xa0 for column zuojiesuan at row 1"
百度的结果是编码问题,我不知道具体怎么解决?

-- coding: utf-8 --

import urllib2
import pymysql
import time
from bs4 import BeautifulSoup

today = time.strftime%Y-%m-%d,time.localtimetime.time

loginHeaders = {

Host:www.czce.com.cn,
User-Agent:Mozilla/5.0 Windows NT 6.1; Win64; x64 AppleWebKit/537.36 KHTML, like Gecko Chrome/51.0.2704.106 Safari/537.36,
Referer:http://www.czce.com.cn/portal/jysj/mrhq/A091101index_1.htm,
Content-Type:text/html,
Connection:keep-alive

}
url=http://www.czce.com.cn/portal...
request = urllib2.Requesturl, headers=loginHeaders
opener = urllib2.build_opener
response = opener.openrequest
content = response.read.decodegbk.replace"</tr>","".replace"<tr>",""
soup = BeautifulSoupcontent,lxml.findAllid="senfe"[0]
table = soup.text.split"n"
conn = pymysql.connecthost="192.168.1.98",user="root",passwd="root",db="test",charset=utf8
cur = conn.cursor

cur.executecreate table zhujiagewangid INT10,

        updatetime TIMESTAMP, 
        collecttime DATE,
        pinzhongyuefen VARCHAR10,
        zuojiesuan DECIMAL10,2,
        jinkaipan DECIMAL10,2,
        zuigaojia DECIMAL10,2,
        zuidijai DECIMAL10,2,
        jinshoupan DECIMAL10,2,
        jinjiesuan DECIMAL10,2,
        zhangdie1 DECIMAL10,2,
        zhangdie2 DECIMAL10,2,
        chengjiaoliang INT10,
        kongpanliang INT10,
        zengjianliang INT10,
        chengjiaoe DECIMAL20,2


for i in range0,8:

value=[today,table[16+14*i],table[17+14*i],table[18+14*i],table[19+14*i],table[20+14*i],
       table[21+14*i],table[22+14*i],table[23+14*i],table[24+14*i],table[25+14*i],
       table[26+14*i],table[27+14*i],table[28+14*i]]

cur.execute"INSERT INTO zhujiagewang"

        "collecttime,pinzhongyuefen,zuojiesuan,jinkaipan,zuigaojia,zuidijai,"
        "jinshoupan,jinjiesuan,zhangdie1,zhangdie2,chengjiaoliang,kongpanliang,zengjianliang,chengjiaoe"
        "VALUES %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",value

conn.commit
cur.close
conn.close

你的做结算这列是DECIMAL类型,你插入一个字符串xa0,当然会报错,你要把xa0转成整数或者浮点数才行啊

栏目列表

广告位

在线博彩导航