Error in manage.py runningerver with Django on windows 8.1

I couldn't find this exit code anywhere, but hopefully one of you could help me or let me know if it's a bug in python / Django.

Anyway, here's the stacktrace first:

    Traceback (most recent call last):
  File "C:\Sitezooi\SiteTest\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\__init_
_.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Program Files\Python\lib\site-packages\django\core\management\__init_
_.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\base.py
", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\base.py
", line 338, in execute
    output = self.handle(*args, **options)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\command
s\runserver.py", line 83, in handle
    self.run(*args, **options)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\command
s\runserver.py", line 92, in run
    autoreload.main(self.inner_run, args, options)
  File "C:\Program Files\Python\lib\site-packages\django\utils\autoreload.py", l
ine 322, in main
    reloader(wrapped_main_func, args, kwargs)
  File "C:\Program Files\Python\lib\site-packages\django\utils\autoreload.py", l
ine 293, in python_reloader
    exit_code = restart_with_reloader()
  File "C:\Program Files\Python\lib\site-packages\django\utils\autoreload.py", l
ine 279, in restart_with_reloader
    exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: inval
id character

      

Ignore the weird file path, I even just tried to put it on C: \ directly.

There might be another similar Stackoverflow question here: UnicodeEncodeError when using a compile function , but it doesn't look like the file path I'm using uses any non-english characters. I tried a couple of solutions but they didn't work.

Running python 3.4.1 tested earlier in 2.7.x didn't work either. Works fine on linux (Ubuntu).

There is nothing special about the django project as it is just an empty project project.

+3


source to share


5 answers


I had the same problem and found a solution. From what I was looking for, this also happens with Windows 7 and 8.

If you want to know in more detail how I ended up checking the ticket I submitted on the Django forums: Error in manage.py runningerver on Windows (7/8 / 8.1) .

Now, to solve this problem, open this file C: \ Program Files \ Python \ lib \ site-packages \ django \ utils \ autoreload.py (I am using your code as a reference) and add this line of code just before your error ( line 279):

new_environ['PATH'] = os.path.abspath(new_environ['PATH'].replace('\u202a', ''))

      



Your function should now look like this:

def restart_with_reloader():
    while True:
        args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv
        if sys.platform == "win32":
            args = ['"%s"' % arg for arg in args]
        new_environ = os.environ.copy()
        new_environ["RUN_MAIN"] = 'true'
        new_environ['PATH'] = os.path.abspath(new_environ['PATH'].replace('\u202a', ''))
        exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
        if exit_code != 3:
            return exit_code

      

Now try using manage.py runningerver again. I hope this solves your problem and don't feel lonely.

+6


source


In my case, it had nothing to PATH

do with what appears to be an environment setting CHROME_RESTART

with some non-english characters. Pulling it out new_environ

did the trick:



def restart_with_reloader():
    while True:
        args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv
        if sys.platform == "win32":
            args = ['"%s"' % arg for arg in args]
        new_environ = os.environ.copy()
        new_environ["RUN_MAIN"] = 'true'

        # This will prevent UnicodeEncodeError
        new_environ.pop("CHROME_RESTART", None)

        exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
        if exit_code != 3:
            return exit_code

      

+3


source


I tried this

new_environ['PATH'] = os.path.abspath(new_environ['PATH'].replace('\u202a', ''))

      

but it didn't work.

And my decision

new_environ['PATH'] = os.path.abspath(new_environ['PATH'].encode('ascii', 'replace'))

      

Hope this helps you!

+2


source


UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1:invalid character

      

I had the same problem on Windows 7 with

$ python manage.py runserver

      

Just in case anyone has a Cyrillic computer name like mine, this is exactly what is causing the encoding problem. So the solution is to rename your computer using only Latin characters.

+1


source


I had the same problem.
The reason was not latin characters in the notation of environment variables.
In my case, it was the Cyrillic name of some folder, and my windows were originally the English version.
So he had a conflict. After removal, everything works fine.

+1


source







All Articles