Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-20 Thread Glenn Linderman

On 11/20/2018 10:49 AM, Tim Roberts wrote:

Glenn Linderman wrote:
Of course, the GetJob is decoding the structure properly... but its 
PyBuildValue parameter strings are much more complex than the 
PyArg_ParseTupleAndKewyords parameter strings, and there is mention 
of TCHAR in the JobToPy, but not in the PyToJob, so that makes it 
further seem like my speculations above might have some chance of 
being the problem.


I should not have scoffed at your speculation, because your analysis 
was correct.  The win32print code is calling SetJobW, which expects 
Unicode, but the JOB_INFO_1 structure is filled with ANSI strings.  
That's a very nasty bug.  I'll file a bug report.


In the meantime, I'll fix up my little C++ example to do the job for you.


Hi Tim,

I understand that it is easy to look at code and think you know what it 
is doing, until the debugger proves otherwise. I've been there plenty of 
times. Fortunately in this case, my speculations were based on _not_ 
thinking I knew what the code was doing, and _not_ having a clue how 
most of the called routines worked, so my mind was freed from such 
restrictions, and I could make a lucky guess!


I appreciate your taking time to follow through.

BTW, Google's email spam filter that hates .zip files can easily be 
circumvented, by adding another extension to the file... as in 
file.zip.removeme


Glenn
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-20 Thread Tim Roberts

Glenn Linderman wrote:
Of course, the GetJob is decoding the structure properly... but its 
PyBuildValue parameter strings are much more complex than the 
PyArg_ParseTupleAndKewyords parameter strings, and there is mention of 
TCHAR in the JobToPy, but not in the PyToJob, so that makes it further 
seem like my speculations above might have some chance of being the 
problem.


I should not have scoffed at your speculation, because your analysis was 
correct.  The win32print code is calling SetJobW, which expects Unicode, 
but the JOB_INFO_1 structure is filled with ANSI strings.  That's a very 
nasty bug.  I'll file a bug report.


In the meantime, I'll fix up my little C++ example to do the job for you.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-20 Thread Tim Roberts

Glenn Linderman wrote:


I looked at the win32print.cpp file. There were lots of 
Python-internals stuff there that I don't really follow well. I didn't 
see anything obviously wrong, but I got to wondering about the code 
that builds the structure... it puts in UTF-8 text strings (which 
would be same as ASCII in the cases I'm considering, but what if 
someone has a non-ASCII printer name, or document file name, or ???). 
And I'm sure the A version of the Windows API probably is happy with 
ASCII, but does the 64-bit compilation call the A version of the 
Windows API or the W version?


32 vs 64 makes no difference here.   SetJobA always expects 8-bit 
strings, SetJobW always expects 16-bit strings.  SetJob maps to one or 
the other based on the absence or presence of #define UNICODE.  The 
routines that convert Python strings to zero-terminated strings will do 
the right thing.



And would the W version be happy with ASCII? Or would that produce an 
1804 error?


If you pass ASCII strings to the W API, it just means the strings are 
interpreted as garbage.  The name will not be found.  It shouldn't cause 
1804.


I went to ReactOS and looked at the source code for SetJob. 
ERROR_INVALID_DATATYPE is returned for exactly one reason: the pDatatype 
value is not in the valid list of datatypes for the print processor for 
this job.  There's no reason for that; your structure says "NT EMF 
1.008", which is almost always valid.


This had to work at some point.  All of these things get tested. I just 
don't know what would have changed.  If I get motivated (I've already 
spent too much time on this ;), I'll see if I can get your script to 
fail here.



And then of course, I've no idea what compilation parameters were 
used, either for your program (which works), or for win32print.cpp 
(which maybe doesn't).


I built mine for non-Unicode.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-20 Thread Glenn Linderman

On 11/19/2018 11:52 AM, Tim Roberts wrote:

Glenn Linderman wrote:


I've not coded up the equivalent C program, as I don't have a C 
compiler installed here, and haven't done any C coding for 8 or 10 
years.


Were you able to reproduce the problem, or is your error analysis 
based on code reading?


I looked at the code.  Plus, I recognized that 1804 is a Windows 
errors code, not a Python error.  Let me see if I can write up a C++ 
test that would be useful for you.


I looked at the win32print.cpp file. There were lots of Python-internals 
stuff there that I don't really follow well. I didn't see anything 
obviously wrong, but I got to wondering about the code that builds the 
structure... it puts in UTF-8 text strings (which would be same as ASCII 
in the cases I'm considering, but what if someone has a non-ASCII 
printer name, or document file name, or ???). And I'm sure the A version 
of the Windows API probably is happy with ASCII, but does the 64-bit 
compilation call the A version of the Windows API or the W version?  And 
would the W version be happy with ASCII? Or would that produce an 1804 
error?


Of course, the GetJob is decoding the structure properly... but its 
PyBuildValue parameter strings are much more complex than the 
PyArg_ParseTupleAndKewyords parameter strings, and there is mention of 
TCHAR in the JobToPy, but not in the PyToJob, so that makes it further 
seem like my speculations above might have some chance of being the problem.


And then of course, I've no idea what compilation parameters were used, 
either for your program (which works), or for win32print.cpp (which 
maybe doesn't).


Glenn
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-19 Thread Tim Roberts

Glenn Linderman wrote:


I've not coded up the equivalent C program, as I don't have a C 
compiler installed here, and haven't done any C coding for 8 or 10 years.


Were you able to reproduce the problem, or is your error analysis 
based on code reading?


I looked at the code.  Plus, I recognized that 1804 is a Windows errors 
code, not a Python error.  Let me see if I can write up a C++ test that 
would be useful for you.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-16 Thread Glenn Linderman

On 11/16/2018 12:08 PM, Tim Roberts wrote:

Glenn Linderman wrote:


Here is the code I'm using. Note that the variables js and rename are 
the control variables if you need to tweak this to run in your 
environment. js contains a substring of an existing document name, 
and the idea is that the document name of the first matching spool 
job having a document name containing that fragment will be changed 
to the content of the rename variable by the code.

...
Here is the error I'm getting:

{'JobId': 27, 'pPrinterName': 'HL6180dw', 'pMachineName': 
'STEPHEN', 'pUserName': 'Glenn', 'pDocument': 'duh', 'pDatatype': 
'NT EMF 1.008', 'pStatus': None, 'Status': 8210, 'Priority': 1, 
'Position': 0, 'TotalPages': 22, 'PagesPrinted': 0, 'Submitted': 
pywintypes.datetime(2018, 11, 14, 21, 1, 27, 882000, 
tzinfo=TimeZoneInfo('GMT Standard Time', True))}

Traceback (most recent call last):
  File "D:\my\py\spool.py", line 109, in 
    win32print.SetJob( phandle, res[ 1 ], 1, jobinfo, 0 )
pywintypes.error: (1804, 'SetJob', 'The specified datatype is invalid.')


That's very odd.  This is not from the Pywin32 code --  it has 
correctly parsed your structure.  That error is coming from the SetJob 
API itself (ERROR_INVALID_DATATYPE).  As an experiment, have you tried 
coding up the exact same sequence as a C program to see if you get the 
same error?



Hi Tim,

Thanks for your response.

I've not coded up the equivalent C program, as I don't have a C compiler 
installed here, and haven't done any C coding for 8 or 10 years.


Were you able to reproduce the problem, or is your error analysis based 
on code reading?


Glenn
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-16 Thread Tim Roberts

Glenn Linderman wrote:


Here is the code I'm using. Note that the variables js and rename are 
the control variables if you need to tweak this to run in your 
environment. js contains a substring of an existing document name, and 
the idea is that the document name of the first matching spool job 
having a document name containing that fragment will be changed to the 
content of the rename variable by the code.

...
Here is the error I'm getting:

{'JobId': 27, 'pPrinterName': 'HL6180dw', 'pMachineName': 
'STEPHEN', 'pUserName': 'Glenn', 'pDocument': 'duh', 'pDatatype': 
'NT EMF 1.008', 'pStatus': None, 'Status': 8210, 'Priority': 1, 
'Position': 0, 'TotalPages': 22, 'PagesPrinted': 0, 'Submitted': 
pywintypes.datetime(2018, 11, 14, 21, 1, 27, 882000, 
tzinfo=TimeZoneInfo('GMT Standard Time', True))}

Traceback (most recent call last):
  File "D:\my\py\spool.py", line 109, in 
    win32print.SetJob( phandle, res[ 1 ], 1, jobinfo, 0 )
pywintypes.error: (1804, 'SetJob', 'The specified datatype is invalid.')


That's very odd.  This is not from the Pywin32 code --  it has correctly 
parsed your structure.  That error is coming from the SetJob API itself 
(ERROR_INVALID_DATATYPE).  As an experiment, have you tried coding up 
the exact same sequence as a C program to see if you get the same error?


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-15 Thread Glenn Linderman
No answers on stackoverflow 
 
so maybe it is a bug I should report here.


I try to change a job name in Win32 spooler using Python 3.6 and 
win32print on Windows 10. [And I tell the spooler to save all my print 
jobs, so there are a bunch in there.]


Here is the code I'm using. Note that the variables js and rename are 
the control variables if you need to tweak this to run in your 
environment. js contains a substring of an existing document name, and 
the idea is that the document name of the first matching spool job 
having a document name containing that fragment will be changed to the 
content of the rename variable by the code.


import sys, os
import time
import win32print
#
def print_job_lister( js='' ):
    """
    Finds a job whose name contains the passed substring.
    """

    res = None
    for p in win32print.EnumPrinters( win32print.PRINTER_ENUM_LOCAL, 
None, 1 ):

    flags, desc, name, comment = p
    showprinter = True

    phandle = win32print.OpenPrinter( name )
    print_jobs = win32print.EnumJobs( phandle, 0, -1, 1 )
    for job in print_jobs:
    document = job["pDocument"]
    if js in document:
    if showprinter:
    print( f'printer => {name}')
    showprinter = False
    print( f'  Document => {document}')
    print( f'  JobId => {job["JobId"]}  Status => 
{job["Status"]}'

   f'  Pages => {job["TotalPages"]}')
    if not res:
    res = ( name, job["JobId"])
    win32print.ClosePrinter( phandle )
    return res
#
if __name__ == '__main__':
    js = '20181114'
    rename = 'foobar'
    res = print_job_lister( js )
    print( res )
    if res:
    phandle = win32print.OpenPrinter( res[ 0 ])
    jobinfo = win32print.GetJob( phandle, res[ 1 ], 1 )
    jobinfo['Position'] = win32print.JOB_POSITION_UNSPECIFIED
    if rename:
    jobinfo['pDocument'] = rename
    print( f'abc {win32print.JOB_POSITION_UNSPECIFIED} {jobinfo}')
    win32print.SetJob( phandle, res[ 1 ], 1, jobinfo, 0 )
    win32print.ClosePrinter( phandle )

Here is the error I'm getting:

{'JobId': 27, 'pPrinterName': 'HL6180dw', 'pMachineName': 'STEPHEN', 
'pUserName': 'Glenn', 'pDocument': 'duh', 'pDatatype': 'NT EMF 1.008', 
'pStatus': None, 'Status': 8210, 'Priority': 1, 'Position': 0, 
'TotalPages': 22, 'PagesPrinted': 0, 'Submitted': 
pywintypes.datetime(2018, 11, 14, 21, 1, 27, 882000, 
tzinfo=TimeZoneInfo('GMT Standard Time', True))}

Traceback (most recent call last):
  File "D:\my\py\spool.py", line 109, in 
    win32print.SetJob( phandle, res[ 1 ], 1, jobinfo, 0 )
pywintypes.error: (1804, 'SetJob', 'The specified datatype is invalid.')

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32