Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-6: ordinal not in range (128) #427

Closed
GoogleCodeExporter opened this issue Aug 24, 2015 · 18 comments

Comments

@GoogleCodeExporter
Copy link

In the old version PyScrypter to check a small function I created an empty 
file, it inserted the function and run the script Ctrl+F9 is not saving it.

Now a new version 2.3.1 and it is translated into Russian. I like it a lot, but 
if you create a new default file's name in Russian "модуль1.py" if you 
press Ctrl+F9 gives an error "UnicodeEncodeError: 'ascii' codec can't encode 
characters in position 1-6: ordinal not in range (128)"
To avoid this error to a file to save Latin.

Also, if a file path is not Russian letters, it displays an error
"UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-9: 
ordinal not in range (128) - it was in previous versions

Pyscrypter ver. 2.3.1
OS: Windows Vista

Original issue reported on code.google.com by Kotya...@gmail.com on 17 Oct 2010 at 8:55

Attachments:

@GoogleCodeExporter
Copy link
Author

I cannot reproduce it here.  You can see in the attached image I am running 
without any issues both saved and unsaved files with greek names.

Is your Windows locale set to Russian?
Are you able to run scripts with russian names and/or paths with the standard 
Python interpreter?

Possible solutions:

a)  You may have to do the following (here it works without that, since 
PyScripter passes Unicode filenames to Python):

If you look the PyScripter help file in the topic "Encoded Python
Source Files" (last paragraph) it tells you how to configure Python to
support other encodings by modifying the site.py file.  This file is
in the lib subdirectory of the Python installation directory.  Find
the function setencoding and make sure that the support locale aware
default string encodings is  on. (see below)

def setencoding():
  """Set the string encoding used by the Unicode implementation.  The
  default is 'ascii', but if you're willing to experiment, you can
  change this."""
  encoding = "ascii" # Default value set by _PyUnicode_Init()
  if 1:  <<<<<<<<<<<<<-------------------------------------
      # Enable to support locale aware default string encodings.
      import locale
      loc = locale.getdefaultlocale ()
      if loc[1]:
          encoding = loc[1]
  if 0:
      # Enable to switch off string to Unicode coercion and implicit
      # Unicode to string conversion.
      encoding = "undefined"
  if encoding != "ascii":
      # On Non-Unicode builds this will raise an AttributeError...
      sys.setdefaultencoding (encoding) # Needs Python Unicode
build !

b) Modify the Russian translation so that new modules are created with English 
names.
-  Get Poedit (google for it)
-  Open default.po in the russian locale with PoEdit
-  Find string "module" and delete the translation
-  Save the file.  (PoEdit automatically compiles the default.po into 
default.mo)

Now when you create a new modules you should see English names.

Please report here the outcome of the above.

Original comment by pyscripter on 17 Oct 2010 at 12:53

  • Changed state: Cannot-Reproduce

Attachments:

@GoogleCodeExporter
Copy link
Author

I think the most likely cause is the Windows locale.

Original comment by pyscripter on 17 Oct 2010 at 12:59

@GoogleCodeExporter
Copy link
Author

Could you please also test with Python 3.x and report back whether you have the 
same issue?

Original comment by pyscripter on 17 Oct 2010 at 1:00

@GoogleCodeExporter
Copy link
Author

working versions of "A" and "B".
I tried to reproduce the same situation on Virtual PC with Windows XP.
python 2.6.5 - bug is present
python 3.1 - no error

Original comment by Kotya...@gmail.com on 17 Oct 2010 at 3:08

Attachments:

@GoogleCodeExporter
Copy link
Author

Have you checked the Windows locale?  Is it Russian?
Have you tried to modify site.py?

Original comment by pyscripter on 17 Oct 2010 at 4:29

@GoogleCodeExporter
Copy link
Author

Yes, I changed the file site.py after this work was ok
and Virual PC and on my laptop with Windows Vista.
Windows locale is Russian.

Original comment by Kotya...@gmail.com on 17 Oct 2010 at 4:57

@GoogleCodeExporter
Copy link
Author

Issue 429 has been merged into this issue.

Original comment by pyscripter on 19 Oct 2010 at 2:04

@GoogleCodeExporter
Copy link
Author

Issue 444 has been merged into this issue.

Original comment by pyscripter on 17 Nov 2010 at 12:50

@GoogleCodeExporter
Copy link
Author

Changing site.py is workaround, but not solution for issue.

Original comment by alex.lab...@gmail.com on 17 Nov 2010 at 3:16

@GoogleCodeExporter
Copy link
Author

Thank you very much! Very helpful. Change one line site.py changed condition,
and it worked.

Original comment by Alexand...@gmail.com on 27 Jan 2011 at 12:07

Attachments:

@GoogleCodeExporter
Copy link
Author

Issue 535 has been merged into this issue.

Original comment by pyscripter on 5 Aug 2011 at 7:47

@GoogleCodeExporter
Copy link
Author

Issue 544 has been merged into this issue.

Original comment by pyscripter on 12 Aug 2011 at 2:37

@GoogleCodeExporter
Copy link
Author

Issue 585 has been merged into this issue.

Original comment by pyscripter on 11 Dec 2011 at 7:06

@GoogleCodeExporter
Copy link
Author

Issue 587 has been merged into this issue.

Original comment by pyscripter on 13 Dec 2011 at 2:59

@GoogleCodeExporter
Copy link
Author

Hi,
I use pyscripter 2.4.3.0, I use the method to modify file in python 2.7 in  
Issue 427 like below:

def setencoding():
"""Set the string encoding used by the Unicode implementation. The
    default is 'ascii', but if you're willing to experiment, you can
    change this."""
    encoding = "ascii" # Default value set by _PyUnicode_Init()
    if 1: <<<<<<<<<<<<<-------------------------------------Change the '0'  
to '1'
    # Enable to support locale aware default string encodings.
    import locale
    loc = locale.getdefaultlocale ()
    if loc[1]:
    encoding = loc[1]
    if 0:
    # Enable to switch off string to Unicode coercion and implicit
    # Unicode to string conversion.
    encoding = "undefined"
    if encoding != "ascii":
    # On Non-Unicode builds this will raise an AttributeError...
    sys.setdefaultencoding (encoding) # Needs Python Unicode
    build !

In python 2.7 (the same as python 2.6), when I am debugging, do not  
prompt: UnicodeEncodeError: 'ascii' codec can't encode characters in  
position 12-13: ordinal not in range(128) now, but the debug behaviour is  
odd, it can't break in the breakpoint, But the "Run to Cursor position"  
(also F4) button can use only once.

In Inssue 587 I say in python 2.6 the debug behaviour is odd, because I  
already change the file site.py in python2.6.


�� Tue, 13 Dec 2011 11:04:02 +0800��<pyscripter@googlecode.com> �:

Original comment by xqt...@gmail.com on 16 Dec 2011 at 7:44

@GoogleCodeExporter
Copy link
Author

I have reopened 587

Original comment by pyscripter on 16 Dec 2011 at 11:06

@GoogleCodeExporter
Copy link
Author

The path to .py file must not have any characters except English.

Original comment by levz...@gmail.com on 27 Oct 2013 at 6:55

@GoogleCodeExporter
Copy link
Author

I have the same issue, what I need to do for avoid him ?

Original comment by kubalie...@gmail.com on 12 Jul 2015 at 4:01

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant