我希望我的逻辑服务器(Python3 + Django + uwsgi + nginx)在Ubuntu服务器启动或重启时自动运行。因此,我编写了一个执行脚本(uwsgi --ini=/data/xxx.ini
),并将其添加到/etc/rc.local
。
然后,我重启服务器,运行逻辑服务器,但当程序打印日志到文件时,python3抛出异常:
Traceback (most recent call last):
File "/usr/lib/python3.4/logging/handlers.py", line 73, in emit
logging.FileHandler.emit(self, record)
File "/usr/lib/python3.4/logging/__init__.py", line 1041, in emit
StreamHandler.emit(self, record)
File "/usr/lib/python3.4/logging/__init__.py", line 984, in emit
self.handleError(record)
File "/usr/lib/python3.4/logging/__init__.py", line 915, in handleError
traceback.print_stack(frame, file=sys.stderr)
File "/usr/lib/python3.4/traceback.py", line 286, in print_stack
print_list(extract_stack(_get_stack(f), limit=limit), file=file)
File "/usr/lib/python3.4/traceback.py", line 30, in print_list
print(item, file=file, end="")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 95-100: ordinal not in range(128)
Call stack:
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/wsgi.py", line 177, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "./carwashing/views/decorators.py", line 65, in _require_login_release
json_resp = views(request, user=token_cache.employee, *args, **kwargs)
当我直接在手册中启动uwsgi时,它运行良好。
答案 0 :(得分:0)
您必须使用虚拟激活码
编写.sh文件
#!/bin/bash
clear
cd /path/to your/virtual environment #path to your virtual environment
. bin/activate #Activate your virtual environment
cd /path/to your/project directory
python manage.py runserver #run django server
然后为此.sh文件编写一个重新启动的cron作业,它将适用于您。
查看此link了解更多详情..