I am trying to Print to USB HP printer through python. I was successfull in printing a text file using Ctrl-P command through gui after setting up CUPS using the WEB method.

Now I am trying to print using python-cups library and this python script,

conn.printFile(printer_name,filename,"print test",{}) .

but I get error

cups.IPPError: (1042,'client-error-document-access-error')

What can I do to fix this?

After fixing the print problem I am now stuck at the print formatting . IT does not printas can viewed in the text file and prints everything on the same line and overlaps the next line data on the same line . cant file any docs in CUPS to determine , print formats such as A4 size , or landscapes .

  • This error is set by the CUPS framework on line 1320 in cups/util.h (in the 2.0.0 version). The comment immediately above says 'Unable to open the print file, cancel the job and return...". My guess is that your filename variable contains something wrong.
    – Bex
    Oct 29, 2014 at 7:29
  • I have named the filename variable as follows filename="/serdata.txt" I am just trying to print a test file and it is in the same directory where the python program is kept . Thanks .
    – user22226
    Oct 29, 2014 at 8:28
  • Was this originally a windows file or was it edited on windows? It would help if we saw the file perhaps you could upload it somewhere we could access it. Oct 30, 2014 at 22:04
  • (If my answer below was useful, please feel free to tell me so. If it was not, please tell me as well, so I can remove it. Thank you!)
    – Bex
    Nov 3, 2014 at 7:02

1 Answer 1


Ok, as it turns out, the file you tried to print was called serdata.txt and placed in the same folder as the python program, but the filename provided to printFile was /serdata.txt. The preceding slash tells the system to look for the file in the root folder, where it could not be found - hence, the cups framework could not access the file, and you got the error (client-error-document-access-error).

What you need to do to fix this is probably just to remove the slash / in the beginning of the file name, and you should be fine.

If that does not work, then give the full path to the file that you can get (when standing in the directory) with

ls -d $PWD/serdata.txt

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.