• <bdo id='t87Jp'></bdo><ul id='t87Jp'></ul>
  • <tfoot id='t87Jp'></tfoot>
    <legend id='t87Jp'><style id='t87Jp'><dir id='t87Jp'><q id='t87Jp'></q></dir></style></legend>

    <small id='t87Jp'></small><noframes id='t87Jp'>

    1. <i id='t87Jp'><tr id='t87Jp'><dt id='t87Jp'><q id='t87Jp'><span id='t87Jp'><b id='t87Jp'><form id='t87Jp'><ins id='t87Jp'></ins><ul id='t87Jp'></ul><sub id='t87Jp'></sub></form><legend id='t87Jp'></legend><bdo id='t87Jp'><pre id='t87Jp'><center id='t87Jp'></center></pre></bdo></b><th id='t87Jp'></th></span></q></dt></tr></i><div id='t87Jp'><tfoot id='t87Jp'></tfoot><dl id='t87Jp'><fieldset id='t87Jp'></fieldset></dl></div>

        Android 上的 kivy/Python 上缺少 Unicode 编解码器?

        时间:2023-08-31

          <i id='323iu'><tr id='323iu'><dt id='323iu'><q id='323iu'><span id='323iu'><b id='323iu'><form id='323iu'><ins id='323iu'></ins><ul id='323iu'></ul><sub id='323iu'></sub></form><legend id='323iu'></legend><bdo id='323iu'><pre id='323iu'><center id='323iu'></center></pre></bdo></b><th id='323iu'></th></span></q></dt></tr></i><div id='323iu'><tfoot id='323iu'></tfoot><dl id='323iu'><fieldset id='323iu'></fieldset></dl></div>
            <bdo id='323iu'></bdo><ul id='323iu'></ul>
            <legend id='323iu'><style id='323iu'><dir id='323iu'><q id='323iu'></q></dir></style></legend>
                <tbody id='323iu'></tbody>

              <tfoot id='323iu'></tfoot>

              <small id='323iu'></small><noframes id='323iu'>

                • 本文介绍了Android 上的 kivy/Python 上缺少 Unicode 编解码器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个在 kivy 下运行的程序,它在 Windows 上运行良好,但在 Android 上打开文件失败(两个平台上都是 1.8.0).奇怪的是,当我明确要求 utf-8 时,错误消息表明它正在尝试解码 ASCII;该文件的任何地方都没有 0xFF 字符 - 我使用 od 实用程序进行了检查.

                  I have a program running under kivy that works fine on Windows but fails on opening a file on Android (1.8.0 on both platforms). The odd thing is that the error message indicates it's trying to decode ASCII when I'm plainly asking for utf-8; also the file doesn't have a 0xFF character anywhere in it - I checked with the od utility.

                  代码:

                  try:
                      Logger.info('Mark: opening file ' + repr(filename))
                      with codecs.open(filename, 'r', encoding='utf_8') as f:
                          lines = [line.rstrip(u'
                  ').lstrip(codecs.BOM) for line in f]
                  except UnicodeDecodeError as e:
                      Logger.info('Mark: utf8 load failed: ' + str(e))
                      with codecs.open(filename, 'r', encoding='cp1252') as f:
                          lines = [line.rstrip(u'
                  ') for line in f]
                  

                  日志文件:

                  [INFO              ] Mark: opening file '/mnt/sdcard/My Files/Documents/DVDs.txt'
                  [INFO              ] Mark: utf8 load failed: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
                  [INFO              ] Base: Leaving application in progress...
                  [WARNING           ] stderr: Traceback (most recent call last):
                  [WARNING           ] stderr:   File "main.py", line 295, in <module>
                  [WARNING           ] stderr:     app.run()
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/app.py", line 792, in run
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/base.py", line 481, in runTouchApp
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/core/window/window_pygame.py", line 381, in mainloop
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/core/window/window_pygame.py", line 287, in _mainloop
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/base.py", line 321, in idle
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/clock.py", line 422, in tick
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/clock.py", line 537, in _process_events
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/clock.py", line 309, in tick
                  [WARNING           ] stderr:   File "main.py", line 266, in select_file_part2
                  [WARNING           ] stderr:     with codecs.open(filename, 'r', encoding='cp1252') as f:
                  [WARNING           ] stderr:   File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/codecs.py", line 884, in open
                  [WARNING           ] stderr: LookupError: unknown encoding: cp1252
                  

                  我放入了一些调试代码以通过 整个列表,发现除了 asciilatin_1 和各种 utf 编解码器之外的所有内容都丢失了.

                  I put in some debugging code to go through the entire list and found that all were missing except ascii, latin_1, and the various utf codecs.

                  推荐答案

                  摆脱try/except,看看真正的异常.codecs.BOM 是一个字节字符串 xffxfe 并且使用默认的 ascii 编解码器强制转换为 Unicode:

                  Get rid of the try/except and look at the real exception. codecs.BOM is a byte string xffxfe and it is being coerced into Unicode using the default ascii codec:

                  >>> import codecs
                  >>> codecs.BOM
                  'xffxfe'
                  >>> u'test'.lstrip(codecs.BOM)
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
                  

                  这篇关于Android 上的 kivy/Python 上缺少 Unicode 编解码器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Android 中从 Java 代码执行 Python 脚本 下一篇:在 Kivy 中处理 Android 上的应用程序暂停/恢复

                  相关文章

                  最新文章

                  <legend id='jz4jA'><style id='jz4jA'><dir id='jz4jA'><q id='jz4jA'></q></dir></style></legend>

                  • <bdo id='jz4jA'></bdo><ul id='jz4jA'></ul>
                • <i id='jz4jA'><tr id='jz4jA'><dt id='jz4jA'><q id='jz4jA'><span id='jz4jA'><b id='jz4jA'><form id='jz4jA'><ins id='jz4jA'></ins><ul id='jz4jA'></ul><sub id='jz4jA'></sub></form><legend id='jz4jA'></legend><bdo id='jz4jA'><pre id='jz4jA'><center id='jz4jA'></center></pre></bdo></b><th id='jz4jA'></th></span></q></dt></tr></i><div id='jz4jA'><tfoot id='jz4jA'></tfoot><dl id='jz4jA'><fieldset id='jz4jA'></fieldset></dl></div>
                • <small id='jz4jA'></small><noframes id='jz4jA'>

                  1. <tfoot id='jz4jA'></tfoot>