从本地计算机更改为虚拟主机时,从python脚本调用pdftotext不起作用 [英] calling pdftotext from python script not working when I change from local machine to my webhosting

查看:136
本文介绍了从本地计算机更改为虚拟主机时,从python脚本调用pdftotext不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小的python脚本来从PDF解析/提取信息.我在本地计算机上对其进行了测试,我具有python 2.6.2和pdftotext版本0.12.4.

I wrote a small python script to parse/extract info from a PDF. I tested it on my local machine, I have python 2.6.2 and pdftotext version 0.12.4.

我正在尝试在我的虚拟主机服务器(dreamhost)上运行它.它具有python版本2.5.2和pdftotext版本3.02.

I am trying to run this on my webhosting server (dreamhost). It has python version 2.5.2 and pdftotext version 3.02.

但是当我尝试运行该脚本时,我在pdftotext行中收到以下错误(我也用一个简单的废弃脚本进行了检查)错误:无法打开文件'-'"

But when I try to run the script I get the following error at the pdftotext line ( I have checked it with a simple throw away script as well) "Error: Couldn't open file '-'"

def ConvertPDFToText(currentPDF):
    pdfData = currentPDF.read()

    tf = os.tmpfile()
    tf.write(pdfData)
    tf.seek(0)

    if (len(pdfData) > 0) :
        out, err = subprocess.Popen(["pdftotext", "-layout", "-", "-"], stdin = tf, stdout=subprocess.PIPE ).communicate()
        return out
    else :
        return None

请注意,我已将此函数传递给相同的PDF文件,并且确实可以访问它.在另一个功能中,我可以通过网络主机上运行的相同脚本通过电子邮件将PDF文档发送给自己.

Note that I am pass this function the same PDF file and it does have access to it. In another function I can email myself the PDF document from the same script running on the webhost.

我做错了什么?我的本地版本和Webhost版本在subprocess/python/pdftext用法上可能有什么区别?我猜我将不得不修改该命令,因此任何帮助将不胜感激.

What am I doing wrong? What is the possible difference in usage for subprocess/python/pdftext between my local version and the webhost version? I am guessing I will have to modify the command, so any help would be greatly appreciated.

谢谢.

推荐答案

可以直接在Webhost上从命令行读取pdftotext吗?你能验证一下吗?另外,为什么不将临时文件的名称作为参数传递而不是在标准输入中给出呢? (根据您的建议在这里用餐).

Can the pdftotext read from the command line directly on webhost? Can you verify this? Also, why don't you pass the name of the temporary file as an argument rather than give it on standard input? (repasting here as per your suggestion).

这篇关于从本地计算机更改为虚拟主机时,从python脚本调用pdftotext不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆