Reputation: 9617
I have deployed my app using some tutorial
I use nginx+gunicorn (also I use systemd)
Right now everything works fine on my dev server
But on production it fails with
Internal Server Error
when I try to download file
How and where can I find gunicorn logs? (I use ubuntu)
Also, this is piece of code that causes an error just in case:
def download_xlsx(request):
user = request.user
file_name = request.GET['file_name']
file_path='main_app/static/xlsx/' + str(user.id) + '/' + file_name
disposition= 'attachment; filename="' +smart_str(file_name) + '"'
disposition=disposition.encode('utf-8')
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = disposition
return response
return projects.to_utf8_json_response('not found')
UPD: I tried to run sudo journalctl -u gunicorn
But I get as a result a huge file starting 2 month ago, so I can't go to latest logs do to it's size
Upvotes: 8
Views: 20081
Reputation: 2796
don't forget to set the encoding in your gunicorn service file (otherwise you can get strange Unicode errors and it looks like you are running into this issue with the function that you described above.)
[service]
Environment="LANG=ru_RU.UTF-8"
this could be a related problem to yours: UnicodeEncodeError [Python3/Gunicorn/Nginx/Django]
Upvotes: 1
Reputation: 9617
Seems to work like this:
journalctl --unit=gunicorn | tail -n 300
Upvotes: 23