【问题标题】:python3 unotools connection error failed to connectpython3 unotools连接错误无法连接
【发布时间】:2016-07-25 22:37:47
【问题描述】:

我已经寻找答案,但到目前为止没有任何帮助。我有一个方法,我想用它来创建一个 odt 文件并用文本填充它。我还希望用户在创建文件时查看它。我正在使用 python 3.4.3 unotools 0.3.3 LinuxMint 17.1 LibreOffice 4.2.8.2

问题:

unotools.errors.ConnectionError: failed to connect: ('socket,host=localhost,port=8100', {})

unotools 示例在终端上运行良好 - 创建并保存了一个 sample.odt,没有错误。我的草稿代码:

def writer_report(self):
    subprocess.Popen(["soffice", "--accept='socket,host=localhost,port=8100;urp;StarOffice.Service'"])
    time.sleep(5)  # using this to give time for LibreOffice to open - temporary
    context = connect(Socket('localhost', '8100'))
    writer = Writer(context)
    writer.set_string_to_end('world\n')
    writer.set_string_to_start('hello\n')
    writer.store_to_url('output.odt','FilterName','writer8')
    writer.close(True)

LibreOffice 应用程序打开并保持打开状态。但是,连接似乎丢失了。
希望有人能给我帮助,谢谢。

【问题讨论】:

    标签: python python-3.x connection libreoffice-writer


    【解决方案1】:

    我不推荐这样的代码:

    subprocess.Popen(...)
    time.sleep(...)
    

    最好用shell脚本启动soffice,然后调用python脚本。

    但是,如果您确定在子进程中运行soffice,那么我建议将睡眠时间增加到至少 15 秒。

    https://forum.openoffice.org/en/forum/viewtopic.php?t=1014

    【讨论】:

    • 感谢您的建议。我试着延长时间,但仍然没有快乐。
    【解决方案2】:

    感谢您的建议。我确实希望它运行一个子进程。我尝试延长时间,但仍然没有快乐。
    我现在正在考虑使用 Python odfpy 1.3.3 包,在开始使用一两天后,我已经取得了更大的成功。

    【讨论】:

      猜你喜欢
      • 2017-08-20
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 2014-02-03
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多