Pycups打印机错误

时间:2015-09-24 03:15:08

标签: python-2.7 printing cups

我试图使用python和pycups来打印文件。

   import cups
conn = cups.Connection()
printers = conn.getPrinters ()
for printer in printers:
    print printer, printers[printer]["device-uri"]
with open('m.txt', 'w')as output:
    output.write('some text')
    print "done" #debugging
    prin = conn.getDefault()
    conn.printFile(prin, 'm.txt', 'm.txt',{})
    print "done 2" # debugging
    output.close()

直到

为止
conn.printFile(prin, 'm.txt', 'm.txt',{})

我得到错误

    Traceback (most recent call last):
  File "print.py", line 10, in <module>
    conn.printFile(prin, 'm.txt', 'm.txt',{})
cups.IPPError: (1024, 'No file in print request.')

但是当我看到m.txt在我的主文件夹中时。

即时通讯使用python 2.7和xbuntu并拥有多台打印机,默认设置为cups-pdf。

我在文档中找不到太多信息

3 个答案:

答案 0 :(得分:0)

尝试使用要打印的文件的绝对路径,即:

os.path.abspath("m.txt")

答案 1 :(得分:0)

在关闭您编写的文件后尝试打印

import os
import cups
conn = cups.Connection()
printers = conn.getPrinters ()
with open('m.txt', 'w')as output:
    output.write('some text')
    print "done" #debugging
    prin = conn.getDefault()
    output.close()
#add script print after close file
f = os.path.abspath("m.txt")
conn.printFile(prin, f, 'm.txt',{})
print "done 2" # debugging

它在我的工作

答案 2 :(得分:0)

我认为出现此错误的原因是,您正在关闭后打印它,因此您需要在打印前关闭该文件。

import cups
conn = cups.Connection()
printers = conn.getPrinters ()
for printer in printers:
    print printer, printers[printer]["device-uri"]
    with open('m.txt', 'w')as output:
        output.write('some text')
        output.close()
        print "done" #debugging
        conn.printFile(printer, 'm.txt', " ", {})
        print "done 2" # debugging