0
我在supervisord下運行uwsgi時遇到了一些問題。在主管中運行uwsgi出錯,但在命令行中順利運行
主要的問題是使用命令行運行uwsgi --ini /home/satori/mysite/src/mysite_uwsgi.ini
,一切順利,但是當我在supervisorctl下運行它時,服務器返回500上傳帶有非ascii字符名稱的文件。
但它不會發生如果我在命令行中運行,文件被正確上載。
我認爲這個問題與我的主管配置文件有關,也許是一些環境問題。我的配置文件是在/etc/supervisord.conf
這是我mysite_uwsgi.ini文件,它在/home/satori/mysite/src/mysite_uwsgi.ini
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/satori/mysite/src
# Django's wsgi file
module = mysite.wsgi
# the virtualenv (full path)
#home = /home/ubuntu/mysite/bin
#plugins = python34
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /home/satori/mysite/src/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
,這是supervisord.conf
[program:mysite]
command=uwsgi --ini /home/satori/mysite/src/mysite_uwsgi.ini
autostart=true
autorestart=true
user=root
log_stderr=true
stdout_logfile=/var/log/mysite.log
相關設置,這是500錯誤:
UnicodeEncodeError at /upload/view/
'ascii' codec can't encode characters in position 37-38: ordinal not in range(128)
models.py
# encoding: utf-8
import os
from django.db import models
from django.conf import settings
def get_upload_path(instance, filename):
filename = ''.join([ch for ch in filename if ord(ch) < 128])
return os.path.join("user_%d" % instance.owner.id, filename)
class Picture(models.Model):
"""This is a small demo using just two fields. The slug field is really not
necessary, but makes the code simpler. ImageField depends on PIL or
pillow (where Pillow is easily installable in a virtualenv. If you have
problems installing pillow, use a more generic FileField instead.
"""
file = models.ImageField(upload_to=get_upload_path)
slug = models.SlugField(max_length=50, blank=True)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
def __str__(self):
return self.file.name
@models.permalink
def get_absolute_url(self):
return ('upload-new',)
def save(self, *args, **kwargs):
self.slug = self.file.name
super(Picture, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
"""delete -- Remove to leave file."""
self.file.delete(False)
super(Picture, self).delete(*args, **kwargs)
感謝您的答覆,但它不工作,雖然。我轉而刪除文件名中的非ASCII字符,它可以正常工作。據我所知,編碼一直是個大問題。 –
然後我將模型添加到問題中,如果您有任何想法發生了什麼,請告訴我。非常感謝。 –
在你的模型中似乎沒有__unicode__方法。添加一個並返回self.file.name。然後添加一個__str__方法,以防您需要它,看起來像我編輯的帖子。這對我有效。 它不應該與你的uwsgi和supervisord有關。儘管我認爲在開發過程中最好將進程設置爲1. –