Ubuntu VM with Cups Server and docker container with pycups: cups.IPPError: (1030, ‘The printer or class does not exist.’)

Ubuntu VM with the cups server installed, configured and running.
I can print (test pages and documents) to every printer and CLASS from the web interface with no problems.

Inside this VM there is a docker container with a python flask app where you can POST pdfs and they get saved in a temporary path.

Then it uses pycups to print those files to a CLASS called “DOCUMENTOS”.
This fails everytime saying:

cups.IPPError: (1030, 'The printer or class does not exist.')

I’ve tried to call directly to the printer (HP_LaserJet_Pro_M118dw) but the result is the same.

In the docker container I have setup a bind:

/tmp -> /tmp

which results in this filename passed to pycups printFile function:

/tmp/print-daemon/1696440073890032106.pdf

Relevant python code:

cups.setServer(cups_server)
cups.setPort(631)
cups.setEncryption(3)
cups.setUser("user")
cups.setPasswordCB(self.__passwordCB)
self.conn = cups.Connection(host=cups_server, port=631)
...
self.conn.printFile(printer="DOCUMENTOS", filename=filename, title="", options={})

Python list printers:

printers = self.conn.getPrinters()
printer_names = list(printers.keys())
print(f'printers {printer_names}', flush=True)

Result in log:

printers ['DOCUMENTOS', 'HP_LaserJet_Pro_M118dw']

lpstat -v:

dispositivo para DOCUMENTOS: ///dev/null
dispositivo para HP_LaserJet_Pro_M118dw: socket://192.168.5.XX

/etc/cups/cupsd.conf

LogLevel debug2
Port 631
Listen /run/cups/cups.sock
Browsing On
BrowseLocalProtocols dnssd
DefaultAuthType Basic
WebInterface Yes
...

/var/log/cups/error_log

D [04/Oct/2023:17:33:13 +0000] Get-Printer-Attributes file:///dev/null
d [04/Oct/2023:17:33:13 +0000] get_printer_attrs(0x5631dc6e8290[6], file:///dev/null)
D [04/Oct/2023:17:33:13 +0000] Get-Printer-Attributes client-error-not-found: The printer or class does not exist.
D [04/Oct/2023:17:33:13 +0000] [Client 6] Returning IPP client-error-not-found for Get-Printer-Attributes (file:///dev/null) from 172.18.0.4.

Pastebin Cupsd full error log

If you miss some info, please ask.

UPDATES

Why is it failing from inside the container? Maybe some permissions (IP address, user, etc.)?

  • Stack Overflow is for programming questions so this is off-topic here. This would be a better fit on one of the other sites like ask ubuntu or superuser.

    – 

  • I have posted this problem on those two other communities you mentioned, but it has a part of pyhon programming and the problem may be there too.

    – 




  • I saw that but I felt this was almost certainly a printer configuration issue. However, I will retract my close vote just in case the problem is in your code.

    – 

  • What have you tried to resolve the problem? Where are you stuck? Would sending a manual print job work, but sending it from Python does not?

    – 

  • As you are running the code inside a Docker container: does printing from that container also work?

    – 

Leave a Comment