cups printing - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: cups printing (/thread-15230.html) |
cups printing - Barrowman - Jan-08-2019 I have a raspberrypi I am using as a print server and it has my HP Officejet on a USB port. I can print to it from libreoffice, gedit and all other programs I use. I am trying to use python-cups and am getting an error which puzzles me as I have being using code just copied and pasted and pointing it to a test file. import cups conn = cups.Connection() printers = conn.getPrinters () prin = conn.getDefault() myfile = "/home/norman/Fred.txt" conn.printFile (prin, myfile, "Project Report", {})I am running it from python 3.5.2 The error is I cannot find out what is wrong because the error doesn't seem specific enough.Can someone explain what is wrong and how to fix it please? RE: cups printing - heiner55 - May-26-2019 #!/usr/bin/python3 import time, pprint, cups conn = cups.Connection() printers = conn.getPrinters () pprint.pprint(printers) print() printer = conn.getDefault() print("Default1:", printer) if printer == None: printer = list(printers.keys())[0] print("Default2:", printer) myfile = "./test.txt" pid = conn.printFile(printer, myfile, "test", {}) while conn.getJobs().get(pid, None) is not None: time.sleep(1) #done RE: cups printing - cthart - Oct-18-2022 @heiner55 That does not answer the question. More than likely @Barrowman didn't have a default printer defined. In that case conn.getDefault() returns None , and then conn.PrintFile() throws that exception.
|