Ich versuche mein Django-Projekt auf die Google Cloud Platform hochzuladen.UnicodeDecodeError: 'utf8' Codec kann Byte 0xc7 in Position 27 nicht dekodieren: ungültiges Fortsetzungsbyte django
Wenn ich laufen
python manage.py runserver
ein Fehler auftritt.
Bis vor einiger Zeit funktionierte es gut.
Nach dem Korrigieren der Codes von nur einer Datei "setting.py" trat der Fehler auf.
Hier ist ein Screenshot Bild unten.
C:\Users\sgc109\PycharmProjects\pyproj\djenv\Scripts\python.exe C:/Users/sgc109/PycharmProjects/pyproj/my_project/manage.py runserver
Traceback (most recent call last):
File "C:/Users/sgc109/PycharmProjects/pyproj/my_project/manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\commands\runserver.py", line 62, in execute
super(Command, self).execute(*args, **options)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\commands\runserver.py", line 101, in handle
self.run(**options)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in run
autoreload.main(self.inner_run, None, options)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\utils\autoreload.py", line 341, in main
reloader(wrapped_main_func, args, kwargs)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\utils\autoreload.py", line 312, in python_reloader
exit_code = restart_with_reloader()
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\utils\autoreload.py", line 294, in restart_with_reloader
str_value = force_bytes(new_environ[key], encoding=encoding)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\site-packages\django\utils\encoding.py", line 124, in force_bytes
return s.decode('utf-8', errors).encode(encoding, errors)
File "C:\Users\sgc109\PycharmProjects\pyproj\djenv\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc7 in position 27: invalid continuation byte
Process finished with exit code 1
Ich tat mein Bestes, um die Lösung auf Google und Stackoverflow zu finden, und
Ich habe versucht, hart für etwas falsch in meinem Code zu finden, aber ich kann nichts finden.
Hier sind meine Verzeichnisstruktur, meine Hauptcodes und die Einstellungen des Projekt-Interpreters. (Weil ich nie andere
geändertCodes in meinem Projekt und die Menge an Codes sind zu viele, ich lade nicht alle
Codes in meinem django Projekt.)
views.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home(request):
return HttpResponse("Hello, world!")
urls.py
from django.conf.urls import url
from django.contrib import admin
from my_app import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home)
]
settings.py
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret key'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'my_app',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'my_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'my_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/DB Project',
'NAME': 'db-project-185409:asia-northeast1:sgc109',
'USER': 'user',
'PASSWORD': 'password',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'static'
manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
Das einzige, was ich denke, ich habe einen Fehler hatte, dass
Ich habe 'pip install' für die Installation von Django und MySQL-Python
nicht in der virtuellen Umgebung und tat in der virtuellen Umgebung wieder.
Aber ich bin mir nicht sicher, ob es den Fehler betrifft.
Vielen Dank für das Lesen meiner Frage.
Added
ich meinen Code auf Fehler und ich fand, dass einige Verzeichnisnamen, das koreanische Wort wurden zu einem gewissen Funktion übergeben wird zu haben, aber ich habe keine Ahnung, warum in der Welt der Name des Verzeichnisses übergeben wird .Ich denke, dass das Verzeichnis, das übergeben wird, keine Beziehung mit dem Verzeichnis meines Django-Projekts hat. Hier sind Screenshots unten.
Added2
fand ich, dass das Verzeichnis eines der Verzeichnisse, die in
Umgebungsvariablen enthalten ist. Also löschte ich dieses Verzeichnis von Umgebungsvariablen
und startete meinen PC neu, dann hat es funktioniert !!
Können Sie Ihre 'manager.py' Datei hier ablegen? –
Sicher, ich habe es jetzt in meiner Frage hinzugefügt. – david
versuchen, eine '# - * - Codierung: utf-8 - * -' auf der Oberseite Ihrer 'manage.py' –