0

everyone.

I try to study django and python. But I have a problem. In my book there is such string:

django-admin.py startproject megaproject

When I try to execute this code, I get next message:

D:\Job\РАН\База Данных. Сомнология>django-admin.py startproject megaproject
Traceback (most recent call last):  

File "C:\Python27\Scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
353, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 357,
 in run_from_argv
    self.stderr.write('%s: %s' % (e.__class__.__name__, e))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 8: ordinal
not in range(128)

This code work in english directory. But I have russian directory next type:

D:\Job\РАН\База Данных. Сомнология

This problem appear due differences encoding into python and cmd. And I cannot conform them. I try change coding into command line and into python. But I have no results. When I change encoding into cmd, I get bad string with strange symbols. When I add concretly encoding in title python-file, I have no result too.

hedgehogues
  • 217
  • 3
  • 21
  • As an aside, if you can move to python 3.x, do so. Its unicode support is more tightly integrated and typically has fewer problems. – tdelaney Mar 27 '16 at 23:01
  • Yes, I know it. But in this book uses only python 2.x, therefore it is very important for me. Thanks. – hedgehogues Mar 27 '16 at 23:03
  • @tdelaney, I'm sorry. I worry about my english. It's bad. Very... Do I have a lot of mistakes in my post? – hedgehogues Mar 27 '16 at 23:07
  • No, I think your post is clearly written... but I can't explain why you have this error. – tdelaney Mar 27 '16 at 23:21
  • This appears to be due to a file path that's encoded as codepage 1251 getting combined with a `unicode` string and thus decoded using the default ASCII encoding. It doesn't appear to be related to either cmd.exe or the Windows console. – Eryk Sun Mar 27 '16 at 23:21
  • @eryksun, What is the reason? – hedgehogues Mar 27 '16 at 23:24
  • I don't use Django and have no idea how `run_from_argv` is implemented or whether `self.argv` is `str` or `unicode`. But in most cases on Windows when a decode uses the ASCII encoding it's due to concatenating an `str` string (maybe encoded as the ANSI/OEM codepage or maybe UTF-8) with a `unicode` string. If it were due to the console codepage, it wouldn't be ASCII. – Eryk Sun Mar 27 '16 at 23:44
  • 1
    The problem may be how python reads file system strings. Its Russian, but is read as a regular ascii string so you get bad chars. [This post](http://stackoverflow.com/questions/2276200/changing-default-encoding-of-python) is an interesting read. You may have luck setting an environment variable before running the commnad by `set PYTHONIOENCODING=cp1251`. If that doesn't work, run python, `import sys` and then look at `sys.stdout.encoding` plus `sys.getfilesystemencoding()` to see if there are other code pages named there. – tdelaney Mar 28 '16 at 00:03

1 Answers1

0

The windows django can not work with Russian catalogs.

hedgehogues
  • 217
  • 3
  • 21