• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            sunrise

            每天不斷學(xué)習(xí),才能不斷提升自己。

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              64 隨筆 :: 0 文章 :: 92 評(píng)論 :: 0 Trackbacks
            本來是為了省事處理數(shù)據(jù)的時(shí)候批量插入,結(jié)果插入的時(shí)候一直不能decode。
            python代碼:
            a=open(r"testdata.txt").read(20)
            print list(a)
            print '=========================================================================================='
            print list(a.decode('utf8'))
            print '=========================================================================================='
            testdata數(shù)據(jù):
            0 1 test 這件衣服設(shè)計(jì)的正好看,正是我想要的 2013/2/23 zh
            0
            2 happys 這件衣服設(shè)計(jì)的正好看,正是我想要的 2013/11/21 zh

            出現(xiàn)的錯(cuò)誤:
            ['\xef', '\xbb', '\xbf', '0', '\t', '1', '\t', 't', 'e', 's', 't', '\t', '\xe8', '\xbf', '\x99', '\xe4', '\xbb', '\xb6', '\xe8', '\xa1']
            ==========================================================================================

            Traceback (most recent call last):
            File
            "E:/designerpage/test.py", line 4, in <module>
            print list(a.decode('utf8'))
            File
            "D:\Python27\lib\encodings\utf_8.py", line 16, in decode
            return codecs.utf_8_decode(input, errors, True)
            UnicodeDecodeError:
            'utf8' codec can't decode bytes in position 18-19: unexpected end of data
            出現(xiàn)錯(cuò)誤的原因是因?yàn)閡tf8格式一般是'\xef', '\xbb', '\xbf'三個(gè)一起出現(xiàn),然后解析的,而在某處不能夠成三個(gè)一組的時(shí)候就會(huì)出現(xiàn)這樣的錯(cuò)誤。如果將20改為18則可以正常執(zhí)行。
            當(dāng)然如果是在python2.6里是可以運(yùn)行的,python2.7就會(huì)出現(xiàn)如上錯(cuò)誤。無比坑爹的bug,查了好久。
            posted on 2013-02-21 16:39 SunRise_at 閱讀(9933) 評(píng)論(2)  編輯 收藏 引用 所屬分類: python解決方案

            評(píng)論

            # re: UnicodeDecodeError: 'utf8' codec can't decode bytes in position 18-19: unexpected end of data 2013-10-16 11:01 opina
            那這個(gè)問題是怎么解決的呢?  回復(fù)  更多評(píng)論
              

            # re: UnicodeDecodeError: 'utf8' codec can't decode bytes in position 18-19: unexpected end of data 2013-10-16 11:02 opina
            Traceback (most recent call last):
            File "C:/Python25/testPaython/terry3.py", line 35, in <module>
            sheet1.write(row,1,customerid.decode('utf8'))
            File "C:\Python25\lib\encodings\utf_8.py", line 16, in decode
            return codecs.utf_8_decode(input, errors, True)
            UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-3: invalid data

            這是我報(bào)的錯(cuò)
            sheet1.write(row,1,customerid.decode('utf8'))
            這個(gè)是報(bào)錯(cuò)行,求解  回復(fù)  更多評(píng)論
              

            国产69精品久久久久9999| 久久精品成人欧美大片 | 久久精品国产2020| A级毛片无码久久精品免费| 激情综合色综合久久综合| 国内精品久久久久久野外| 日韩精品久久久肉伦网站| 亚洲精品tv久久久久| 国产精品99久久精品爆乳| 亚洲国产香蕉人人爽成AV片久久| 久久婷婷五月综合97色直播| 色综合久久久久无码专区| 狠狠色综合网站久久久久久久高清 | 久久综合亚洲色HEZYO社区| 色综合久久中文字幕综合网| 久久九色综合九色99伊人| 久久人做人爽一区二区三区| 国产精品久久久久无码av| 国产精品99久久久久久人| 久久久久亚洲AV成人网人人软件 | 怡红院日本一道日本久久| 久久香蕉国产线看观看乱码| 99久久国产综合精品麻豆| 久久免费99精品国产自在现线| 亚洲级αV无码毛片久久精品 | 久久se精品一区二区影院| 亚洲欧美伊人久久综合一区二区| 99久久国产免费福利| 精品免费久久久久国产一区| 亚洲AV日韩精品久久久久| 久久本道久久综合伊人| 97久久超碰成人精品网站| 久久久久国产精品人妻| 久久精品一区二区影院| 久久777国产线看观看精品| 日韩精品久久无码中文字幕| 一级a性色生活片久久无| 久久av高潮av无码av喷吹| 久久97精品久久久久久久不卡| 18岁日韩内射颜射午夜久久成人| 久久综合色区|