• <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 閱讀(9942) 評論(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'))
            這個是報錯行,求解  回復  更多評論
              

            久久99国产精品久久99果冻传媒| 久久97久久97精品免视看 | 麻豆久久久9性大片| 一级a性色生活片久久无| 色狠狠久久综合网| 国产精品久久久久无码av| 久久久久免费视频| 久久精品国产亚洲AV无码娇色| 久久99久久99小草精品免视看| 久久精品国产久精国产| 99久久精品免费看国产一区二区三区| 久久久无码精品亚洲日韩蜜臀浪潮| 精品人妻伦九区久久AAA片69| 久久无码专区国产精品发布| 亚洲国产精品久久66| 蜜臀av性久久久久蜜臀aⅴ| 久久国产影院| 天天综合久久久网| 亚洲AV无码久久精品狠狠爱浪潮| 94久久国产乱子伦精品免费| 久久99精品久久久久久久久久| 久久伊人精品青青草原日本| 亚洲国产精品久久久久| 国产美女久久精品香蕉69| 久久精品国产亚洲AV香蕉| 久久中文精品无码中文字幕| 97精品国产97久久久久久免费| 午夜久久久久久禁播电影| 久久受www免费人成_看片中文| 国产精品免费久久| 国产精品美女久久久久av爽| 久久精品国产亚洲综合色| 久久精品国产亚洲AV电影| 精品无码久久久久国产动漫3d| 亚洲国产一成久久精品国产成人综合 | 2021久久国自产拍精品| 青青草原精品99久久精品66 | 久久天天躁狠狠躁夜夜不卡| 国产亚洲精午夜久久久久久| 精品久久久久中文字幕一区| 国产福利电影一区二区三区,免费久久久久久久精 |