alexmorozov / templated-docs

Generate PDF, MS Word and Excel documents from templates in Django
MIT License
114 stars 57 forks source link

File generation works in development but times out on the server #14

Open RossLYoung opened 7 years ago

RossLYoung commented 7 years ago

Description

I can successfully generate .docx files in development (Ubuntu 16.04), but it hangs/times out on when deployed to the server (Ubuntu 14.04). I have tried LO versions 5.1.6.2 and 5.3.2.2. Nginx & Gunicorn timeouts are 120s. It will successfully generate the templates in 2-3 seconds on my laptop, so the timeout is not the issue. The processor is idle throughout.

Edit: It seems I am able to create .odt files, but not .doc. or .docx on the server.

What I Did

I've added logging to every step of process and discovered that it doesn't seem to get past

https://github.com/alexmorozov/templated-docs/blob/master/templated_docs/__init__.py#L92

This would indicate a problem with LO.

On the server, I can successfully convert an .odt file to .docx with the pylokit example...

>>> import os
>>> lo_path = "/usr/lib/libreoffice/program"
>>> with Office(lo_path) as lo:
...     with lo.documentLoad("report_end_of_course.odt") as doc:
...         doc.saveAs("myNewFile.docx")

Is there anything I can try to debug this further?

Thanks

AnSharypov commented 7 years ago

@RossLYoung Hi Did you find solution for debuging?

RossLYoung commented 7 years ago

@AnSharipov No solution. As above, everything works in development on the laptop. On the server templated-docs can't convert odt to doc/docx. It just hangs. On the server, I can manually convert to doc/docx using the pylokit example. It's very strange.

AnSharypov commented 7 years ago

@RossLYoung I have the same problem. I use your way to convert files and it works. How do you download file after its converted?

minidron commented 7 years ago

I have the same problem.

After some research, I found the problem. uWSGI runs with uid www-data. Libreoffice can't create .config in HOME directory of www-data user, because www-data don't have permission for that.

I did:

sudo mkdir /home/www-data
sudo usermod -d /home/www-data www-data
sudo chown www-data:www-data /home/www-data

Or you can try:

sudo chown -R www-data:www-data /var/www

It helped me. Sorry for my English. :blush:

AnSharypov commented 7 years ago

Hi @minidron thank you for your help! I tried both ways, but still getting 502 error. home and www-data doesn't contain .config file

minidron commented 7 years ago

@AnSharypov

Try this:

AnSharypov commented 7 years ago

@minidron I forgot to mention I use Gunicorn

minidron commented 7 years ago

@AnSharypov If you want, you can write here your email, I send you email with my VK profile and try there help you.

AnSharypov commented 7 years ago

@minidron https://vk.com/andreysharipov it would be great!