I have some problem running uwsgi under supervisord.
The main problem is that with command line, I run uwsgi --ini /home/satori/mysite/src/mysite_uwsgi.ini
, everythings goes well, but when I run it under supervisorctl, the server returned 500 when I upload a file with non-ascii character name.
But it won't happen if I run in the command line, the file is correctly uploaded.
I think the problen is related to my supervisor config file, maybe some environment issues. My config file is in /etc/supervisord.conf
This is my mysite_uwsgi.ini file, it's in /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
and this is the related settings in 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
And this is the 500 error:
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)