4

I have a python program where I try to send a document to a printer. It works fine in my machine with a local printer set as the default printer and connected with my laptop via USB. However, when I tried it with another computer with its default printer being in a network it doesn't work. The error I get is:

pywintypes.error: (31, 'ShellExecute', 'A device attached to the system is not functioning.')

The piece of code is giving problems is the following one:

win32api.ShellExecute(0,"print",doc_path,None,".",0)

I think the problem is because of the printer being connected using the network and not the USB, but it might be another thing.

Thanks for any help.

Ignacio
  • 386
  • 4
  • 19
  • ShellExecute has useless error handling. Use ShellExecuteEx. – David Heffernan Mar 16 '16 at 06:11
  • 1
    I couldn't find the ShellExecuteEx in the win32api module. However, I found the cause of the error: the computer didn't have a pdf reader and that was causing that error somehow (the file to print was a pdf). Installing Foxit reader in that computer fixed the problem. – Ignacio Mar 16 '16 at 20:20
  • You can post the findings from your comment as an answer and accept the answer! – user1251007 Nov 07 '19 at 12:00

3 Answers3

6

I found the cause of the error: the computer didn't have a pdf reader installed and that was causing that error (the file to print was a pdf).

Installing Foxit reader (and making it the default program to open pdfs) fixed the problem.

Ignacio
  • 386
  • 4
  • 19
0

I've got this error when executing a simple print() command but in a command window with utf-8 enabled via the following commands:

chcp 65001

set PYTHONIOENCODING=UTF-8

This caused the error; probably because the string python tried to print on the terminal was in a different encodign than utf-8.

Raul Luna
  • 1,945
  • 1
  • 17
  • 26
0

I had the same problem. Simply installing a pdf reader wasn't enough though, I had to make it the default program to open pdfs too to get it to work.

  • I edited my answer as I also did that when I solved the problem but it was not part of the answer. Thanks for sharing. – Ignacio Mar 31 '21 at 06:25