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

            精品永久久福利一区二区| 性色欲网站人妻丰满中文久久不卡| 7777精品伊人久久久大香线蕉| 久久这里都是精品| 国产成人久久精品一区二区三区 | 久久九九青青国产精品| 日韩一区二区久久久久久 | 久久久WWW成人免费毛片| 久久综合亚洲鲁鲁五月天| 国产99久久精品一区二区| 欧美日韩精品久久久免费观看| 无码伊人66久久大杳蕉网站谷歌| AA级片免费看视频久久| 无码国内精品久久人妻蜜桃| 国产精品99久久久久久猫咪| 久久男人中文字幕资源站| 亚洲国产精品无码久久98| 久久综合一区二区无码| 91久久精一区二区三区大全| 久久久久久精品成人免费图片| 久久噜噜电影你懂的| 亚洲国产一成人久久精品| 久久久久久极精品久久久| MM131亚洲国产美女久久| 看久久久久久a级毛片| 99久久这里只精品国产免费| 精品视频久久久久| 亚洲一本综合久久| 久久99国产精品久久久| 日韩人妻无码精品久久免费一| 亚洲国产视频久久| 久久午夜综合久久| 亚洲国产高清精品线久久| 久久久久久A亚洲欧洲AV冫| 久久久国产一区二区三区| 国产综合免费精品久久久| 久久精品国产精品亚洲下载| 久久WWW免费人成—看片| 国产精品99久久久久久www| 久久久久无码专区亚洲av| 国产三级精品久久|