montypython76
Posts: 3
Joined: Sun Jun 11, 2017 2:28 pm

"lp: not allowed to print" when using a python script

Sun Jun 11, 2017 2:40 pm

Hi there,

I hve an issue printing a textfile with a python script. The script is simple:

Code: Select all

import os

os.system('lp "testdatei.txt"')
But instead of a clean print I get the error above. Tried also with "sudo". Using 'lp "testdatei.txt"' directly in a terminal windows works perfectly. Even using the code above within the python interactive mode works, but not as a script. User "pi" is in the lp group. I have no idea were the right problem exists.

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: "lp: not allowed to print" when using a python script

Sun Jun 11, 2017 3:31 pm

Use subprocess instead.

Dave.
Apple say... Monkey do !!

montypython76
Posts: 3
Joined: Sun Jun 11, 2017 2:28 pm

Re: "lp: not allowed to print" when using a python script

Mon Jun 12, 2017 12:16 pm

Testet the following, but got the same error message:

Code: Select all

subprocess.Popen(['lp','alarm.txt'])

montypython76
Posts: 3
Joined: Sun Jun 11, 2017 2:28 pm

Re: "lp: not allowed to print" when using a python script

Mon Jun 12, 2017 6:22 pm

Found the solution:

1. I installed the package "cups-bsd" to try the correct "lpr" command. But this also turns out the error message.

2. I changed the code to explicitly set the user pi for the printjob:

Code: Select all

os.system ('lpr -U pi testdatei.txt')
Voila... works.

Return to “Python”