Giter Site home page Giter Site logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
The fix seems in Python-2.6.2/Python/bltinmodule.c to change:

#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
const char *Py_FileSystemDefaultEncoding = "mbcs";
#elif defined(__APPLE__)
const char *Py_FileSystemDefaultEncoding = "utf-8";
#else
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
#endif

To:

#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
const char *Py_FileSystemDefaultEncoding = "mbcs";
#elif defined(__APPLE__)
const char *Py_FileSystemDefaultEncoding = "utf-8";
#else
const char *Py_FileSystemDefaultEncoding = "utf-8"; /* use default */
#endif

Source: 
https://github.com/kivy/python-for-android/commit/c3b84199cdf7952d6b3cedb54130a1
988b099107

Original comment by [email protected] on 30 Mar 2012 at 9:48

from python-for-android.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
I try this patch and rebuid Python 2.6.2, not fixing.

Original comment by [email protected] on 18 Apr 2012 at 2:57

from python-for-android.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
Have you tried encoding/decoding paths in your own code, e.g. 
some_string.encode('utf-8') ?

Please post some example code that shows the errors you are referring to.

Original comment by [email protected] on 21 Apr 2012 at 3:06

from python-for-android.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
Hello,

I'm having the same problem. With an application for parsing a xml, I got 
UnicodeEncodeError when picking a non-ascii character.

print sys.getfilesystemencoding() gives me also "None" on SL4A, while on 
Windows gives me "mbcs" (python 2.6 and 2.7) and Linux "UTF-8" (python 2.7).

I leave here an example (sorry if the code is not very clean, but I'm just 
starting to work with python):
http://goo.gl/XWqfj 
http://goo.gl/ylwtS 

Both in Linux and Windows, works without problems. With SL4A and Python 2.6.2:
UnicodeEncodeError: 'ascii' codec can not encode character u '\ XE7' in 
position 98: ordinal not in range (128)

I have also tried a few workarounds, such as distrito2.encode('utf8') or 
repr(distrito2), but without success.

There is already a solution?

Thank you very much!

Best regards,
Pedro

Original comment by [email protected] on 17 Aug 2012 at 11:29

from python-for-android.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
Locale is broken so you would need to wrap with smth like:

_ENCODING = sys.getfilesystemencoding() or locale.getdefaultlocale()[1] or 
'utf-8'

try:
  my_stuff(string)
except (UnicodeEncodeError, UnicodeDecodeError):
  my_stuff(string.encode(_ENCODING))


Original comment by [email protected] on 17 Aug 2012 at 8:35

from python-for-android.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
Hello Anthony,

It worked with _ENCODING = 'utf-8'

Thank you very much!

Best regards,
Pedro

Original comment by [email protected] on 17 Aug 2012 at 11:35

from python-for-android.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
>I try this patch and rebuid Python 2.6.2, not fixing.

I probably mistaked there as I rebuilt Python 2.7.2 with this patch and it 
fixed.

You can build Python 2.7.2 with this patch (IPv6 patch too) there: 
http://code.google.com/p/android-python27/source/browse/#hg%2Fpython-build ; or 
you can use directly the already built version: 
http://code.google.com/p/android-python27/source/browse/#hg%2Fapk%2Fres%2Fraw

And use it with SL4A, package.sh builds python_27.zip and python_extras_27.zip 
(replacement for python_r16.zip and python_extras_r14.zip)

Original comment by [email protected] on 18 Aug 2012 at 1:26

from python-for-android.

kuri65536 avatar kuri65536 commented on June 27, 2024
  • python 2.7.9 => ok 'ascii'
  • python 3.4.3 => ok 'utf-8'

from python-for-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.