centos+flask+unoconv报错

一、在 centos7.4 服务器上部署web服务,里面调用了 unoconv 命令,实现pdf 与 word 的转换。开启多线程时报错:

1.未转换成PDF。但是unoconv没有报错,提示找不到文件,
ERROR in app: Exception on /compare [POST]
FileNotFoundError: [Errno 2] No such file or directory: ‘/data/PythonProject/文档内容修订检测/upload/20190617_17:11:33.169823_Ubuntuf_0.pdf’

2.Error: Unable to connect or start own listener. Aborting.

  • 解决—>
    unoconv依赖的一个服务:soffice.bin出现好多进程并且没自动关闭;
    执行ps -ef | grep soffice.bin会发现一堆进程;
    解决方案就是将这些进程全部杀掉;

3.unoconv: UnoException during import phase: The document ‘file:///data/PythonProject/%E6%968B/upload/69017_aaf_1.doc’ could not
be opened.

4.Traceback (most recent call last): File “/data/python36/bin/unoconv”, line 1195, in
run()
File “/data/python36/bin/unoconv”, line 1189, in run
main()
File “/data/python36/bin/unoconv”, line 1082, in main
convertor.convert(inputfn)
File “/data/python36/bin/unoconv”, line 929, in convert
raise UnoException(“Unable to store document to %s (ErrCode %d)\n\nProperties: %s” % (outputurl, e.ErrCode, outputpro File"/usr/lib64/python2.7/site-packages/uno.py", line 507, in uno_struct__getattr_
return getattr(self.dict[“value”], name)
AttributeError: ErrCode

5.Application Error
unoconv: RuntimeException during export phase:
Office probably died. illegal object given! Office probably died.
Binary URP bridge already disposed
uno.DisposedException: Binary URP bridge disposed during call

Fatal exception: Signal 6 Stack:
/usr/lib64/libreoffice/program/libuno_sal.so.3(+0x3ae30)[0x7f8517aa3e30]
/usr/lib64/libreoffice/program/libuno_sal.so.3(+0x3afa1)[0x7f8517aa3fa1]
/lib64/libc.so.6(+0x35270)[0x7f851741e270]
/lib64/libc.so.6(gsignal+0x37)[0x7f851741e1f7] unoconv:
RuntimeException during update-indexes phase: Office probably died.
Binary URP bridge disposed during
call/lib64/libc.so.6(abort+0x148)[0x7f851741f8e8]
/usr/lib64/libreoffice/program/libvcllo.so(+0x5b2d55)[0x7f850fd78d55]
/usr/lib64/libreoffice/program/libvcllo.so(_ZN11Application5AbortERKN3rtl8OUStringE+0x9a)[0x7f850fcec59a]

收集了网友的一众解决方法:

  • unoconv 版本太低,libreoffice / openoffice /python版本不适配等等

安装unoconv :
pip install unoconv (现在是0.8.2版本)
unoconv -V 后,

unoconv 0.8.2
Written by Dag Wieers [email protected]
Homepage at http://dag.wieers.com/home-made/unoconv/
platform posix/linux
python 3.5.5 (default, Jan 24 2019, 09:05:38)
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
LibreOffice 6.2.0.3

unoconv-pypi:参考资料

二、unoconv 转换时报错:

unoconv: Cannot find a suitable pyuno library and python binary combination in /usr/lib64/libreoffice
ERROR: cannot import name 'Element’

解决:
unoconv 安装位置:~/anaconda3py36/bin/unoconv
/usr/bin/unoconv

  1. 调试模式:unconv -vvv 显示文件位置信息
    执行:unoconv -vvv -f pdf /home/260190/文档/1.docx
    centos+flask+unoconv报错_第1张图片
    libreoffice path:默认安装位置

Using office base path: /opt/libreoffice6.2
Using office binary path: /opt/libreoffice6.2/program

  1. 执行 :UNO_PATH=/opt/libreoffice6.2 unoconv -vvv -f pdf /home/260190/文档/1.docx ,添加 UNO_PATHcentos+flask+unoconv报错_第2张图片
    不会再提示
    unoconv: Cannot find a suitable pyuno library and python binary combination in /usr/lib64/libreoffice
    ERROR: cannot import name ‘Element’

解决方案是使用您要使用的Libreoffice安装附带的python可执行文件运行unoconv,如下。但是这种情况只有多个LibreOffice和/或Python安装才会发生。

UNOPATH=/path/to/Libreoffice /path/to/Libreoffice/program/python /usr/bin/unoconv ....

附:其他方法 ,vim /usr/bin/unoconv , 替换第一行为 #!/usr/bin/python . 指向已安装的python。

参考:
1、https://github.com/unoconv/unoconv/issues/49
2、github-unoconv
3、https://stackoverflow.com/questions/19197534/problems-with-calling-unoconv-from-a-django-app-running-in-an-virtualenv

你可能感兴趣的:(python,flask,centos7)