1

UnicodeDecodeErrorを発生させるのはなぜですか?apacheを使用して静的ファイルをコピーし、次のように入力してdjangoアプリをデプロイしようとしています

$python manage.py collectstatic

以下のようなエラーメッセージが表示されました。

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
collected = self.collect()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 104, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 137, in list
for path in utils.get_files(storage, ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 37, in get_files
for fn in get_files(storage, ignore_patterns, dir):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 37, in get_files
for fn in get_files(storage, ignore_patterns, dir):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 25, in get_files
directories, files = storage.listdir(location)
File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 236, in listdir
if os.path.isdir(os.path.join(path, entry)):
File "/usr/lib/python2.7/posixpath.py", line 71, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xba in position 1: ordinal not in range(128)

静的ファイルの何が問題になっていますか?私のsettings.py

import os
PROJECT_ROOT = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'


STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

およびapachehostconf

ServerName www.abcd.org
DocumentRoot /srv/www/yyy

<Directory /srv/www/yyy>
    Order allow,deny 
    Allow from all 
</Directory>

WSGIDaemonProcess yyy.djangoserver processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup iii.djangoserver

WSGIScriptAlias / /srv/www/yyy/apache/django.wsgi

4

2 に答える 2

3

コピーされる静的ファイルへの1つ以上のパスにASCII以外の文字が含まれているようです。

これは、desctinationディレクトリへのパスとは何の関係もありません。

見つけるための1つの方法は置くことです

try:
    print path
except:
    pass
try:
    print entry
except:
    pass  

/usr/local/lib/python2.7/dist-packages/django/core/files/storage.pyの236行目の直前で、しばらくしてから、manage.pyを再度実行します。

次に、問題が発生した場所を確認する必要があります(犯人は表示されませんが、その直前のファイルと、問題のあるファイルのディレクトリが表示されます)。

または、代わりに、pdbを使用できます

python -m pdb manage.py collectstatic

デバッガーで問題の原因となっているファイルを確認します。

于 2012-08-11T16:03:47.593 に答える
0

Dockerコンテナ内でdjango-pipelineを使用したときにも同じエラーが発生しました。何らかの理由で、システムがPOSIXロケールを使用していることが判明しました。ここで提案したソリューションを使用し、システムシェルにロケール設定をエクスポートしました。

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

その後、ロケールが次のようになることを確認できます。

vagrant@vagrant-ubuntu-trusty-64:/project$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

それはうまくいきました。また、Dockerと外部マシンの両方でそれを行ったことに注意してください。

于 2016-03-29T08:34:01.750 に答える