[python-win32] Q: error when using win32print via apache: "nullcontext handle"

Mark Hammond mhammond at skippinet.com.au
Tue Aug 21 02:05:43 CEST 2007


> This falls under the "myopic-leading-the-blind" department. ;-) I'm
> helping
> a friend who wants to have his web site send something directly to his
> printer when a web form is submitted. We're working with Windoze XP,
> Apache2, and Python 2.4.
> 
> He has two printers, one directly connected and another one on a
> network.
> When run directly from the command line, my code has no problems
> printing
> to either printer. However, when printing via the web, it prints to the
> local printer okay but gives the following error, in the apache
> error.log,
> when printing to the network printer (edited for brevity).
> 
> > jobID = StartDocPrinter(lpr, 1, ("Delivery",None,None))
> > pywintypes.error: (1775, 'StartDocPrinter', 'A null context handle
> was
> > passed from the client to the host during a remote procedure call.')

The problem is almost certainly that the user running the Apache service
does not have the rights to access network resources.  You probably do not
want to change Apache to use a user with more permissions and I'm not sure
if relaxing the permissions for the shared printer (a) is any better or (b)
would even work anyway.  You can probably verify that is the problem by
changing the user configured to run Apache, and then look beyond the Python
and Apache universes for a general solution to this problem.

Mark



More information about the python-win32 mailing list