Python win32 ShellExecute 错误 31:“连接到系统的设备无法正常运行." [英] Python win32 ShellExecute error 31: 'A device attached to the system is not functioning.'
问题描述
我有一个 python 程序,我尝试将文档发送到打印机.它在我的机器上运行良好,本地打印机设置为默认打印机并通过 USB 连接到我的笔记本电脑.但是,当我在另一台计算机上尝试使用它的默认打印机在网络中时,它不起作用.我得到的错误是:
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', '连接到系统的设备无法运行.')
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)
我认为问题是因为打印机是使用网络而不是 USB 连接的,但这可能是另一回事.
I think the problem is because of the printer being connected using the network and not the USB, but it might be another thing.
感谢您的帮助.
推荐答案
我找到了错误的原因:计算机没有安装 pdf 阅读器,这导致了该错误(要打印的文件是 pdf).
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).
安装 Foxit 阅读器(并使其成为打开 pdf 的默认程序)解决了这个问题.
Installing Foxit reader (and making it the default program to open pdfs) fixed the problem.
这篇关于Python win32 ShellExecute 错误 31:“连接到系统的设备无法正常运行."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!