• <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

            每天不斷學習,才能不斷提升自己。

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

            出現的錯誤:
            ['\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
            出現錯誤的原因是因為utf8格式一般是'\xef', '\xbb', '\xbf'三個一起出現,然后解析的,而在某處不能夠成三個一組的時候就會出現這樣的錯誤。如果將20改為18則可以正常執行。
            當然如果是在python2.6里是可以運行的,python2.7就會出現如上錯誤。無比坑爹的bug,查了好久。
            posted on 2013-02-21 16:39 SunRise_at 閱讀(9934) 評論(2)  編輯 收藏 引用 所屬分類: python解決方案

            評論

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

            # 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

            這是我報的錯
            sheet1.write(row,1,customerid.decode('utf8'))
            這個是報錯行,求解  回復  更多評論
              

            中文字幕一区二区三区久久网站| 一本一道久久a久久精品综合| 久久青青草视频| 久久久久久国产精品无码下载| 久久精品日日躁夜夜躁欧美| 国产成人久久AV免费| 久久99精品久久久久久秒播| 狠狠色狠狠色综合久久| 久久成人精品视频| 亚洲国产精品狼友中文久久久| 久久久久久久亚洲Av无码| 国産精品久久久久久久| 欧美精品久久久久久久自慰| 久久婷婷国产麻豆91天堂| 久久午夜福利电影| 99久久精品国产高清一区二区| 久久人人爽人人爽人人片AV东京热| 亚洲色婷婷综合久久| 国产精自产拍久久久久久蜜| 午夜精品久久久久久久久| 国产三级精品久久| 波多野结衣中文字幕久久| 久久99久国产麻精品66| 精品无码久久久久久久动漫| 久久人人爽爽爽人久久久| 久久久久久亚洲精品影院| 久久播电影网| 精品无码久久久久久久动漫| 久久国产精品久久精品国产| 无码人妻久久一区二区三区免费| 亚洲精品成人久久久| 久久夜色精品国产| 色婷婷狠狠久久综合五月| 久久高清一级毛片| 久久久精品波多野结衣| 品成人欧美大片久久国产欧美...| A狠狠久久蜜臀婷色中文网| 九九精品99久久久香蕉| 77777亚洲午夜久久多喷| 精品无码久久久久国产| 久久99久久99小草精品免视看|