Python win32 ShellExecute error 31: 'A device attached to the system is not functioning.' - python-3.x

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.

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.

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.

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.

Related

Mac executable not working when downloaded online

I have made a small (8 MB) program into a MAC executable (.app?)
It works great if I share it using a thumbstick, but if I try to upload it to google drive and then download it it doesn't work. By this I mean It first tells me that It is an unidentified source (this seems reasonable)
But then if I click "open"
It opens as a text file with junk data:
If I try to force it to open on the terminal, how the other program opens, it just shows the heartbeat thing that MACs do when opening a file, but never opens anything.
It is certifiably the same exact file. Same size, same name, same goobldygoop if I open both of them as text files instead of executables.
I am really confused, the only thing I can think of is the "signature" that apple uses is lost when it is compressed into a zip, but I'm probably totally off base.
The code uses python 3.7, pyinstaller, pynput, and selenium.
I am using MAC OS Catalina to write and make into an EXE, then another Catalina to try to run the program.
EDIT: Clarify what doesn't work means
Please help.
I found the answer, simply zip the file from my mac and send it that way!
Yay!

TeraTerm Invalid Host when running .ttl file

Running on a new Windows install. I installed tera Term and copied over a .ttl file I used on a previous windows version. When I try to launch the macro I get an Invalid Host pop-up error.
I can open Tera Term as normal and connect to the host defined in my .ttl file without any problems, it's only when I try to run my script.
I've tested this on both Tera Term Version 4.78 as well as Version 4.105
After some messing around I managed to solve this problem, giving it a real answer so that hopefully if someone else has this problem they will find this.
The problem was that by default my .ttl files were set to open with Tera Term I instead had to set it to open with Tera Term Macro Interpreter, which is an executable that lives in your Tera Term install directory.

creating PNG plots on the linux terminal

I have an R script that I run on a linux server (Debian Wheezy 7.7). This script is meant to do some computations and generate plots into PNGs. Unfortunatelly I get an error:
> savePlot("myplot", "png")
Error in savePlot("myplot", "png") :
can only copy from 'X11(type="*cairo")' devices
How do I get around this? I am only connected from Win XP with PuTTy, I don't have any X-windows set up on my XP and I don't want to bother with this - all I need is to run the script and produce the PNGs. Thanks!
You may have more luck calling the device internally:
png("plot.png")
plot(1)
dev.off()
If you don't want to bother with opening an instance of R, you could save the above script (e.g. "script.01.R") and run the following from the console:
R CMD BATCH script.01.R
This should also work to create the .png.
On my Ubuntu distribution, calling x11() before plot() resolved this issue. This blog post gives more details on different operating systems.

Error on file save: "Opening output file: resource temporarily unavailable"

About 10% of the time, when I attempt to save my file in Emacs I get the following error:
Opening output file: resource temporarily unavailable,
I'm currently using Emacs GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) on
Ubuntu 12.04. I've also verified that this issue occurs logged in as a different user and using Emacs 23.3.1.
This issue gets to be a real pain when I make a fix, attempt to save, and then wonder why my fix didn't happen.... only to find out later that the Emacs save was never successful.
If I notice it happen, I'll keep hitting Ctrl-x Ctrl-s until a save actually goes through (takes a few times).
Does anyone have any idea why this happens and how to prevent it?
Update:
(More info per request)
I'm currently on a Ruby on Rails project and have been getting the error while editing a variety of file types *.rb, *js.coffee, *js.erb, *html.erb, etc.
The files I receive the error on are always files local to my machine. I haven't tested remote files.
If I look at the *messages buffer, for every time the error message occurred, the error is prefixed with: save-buffer-2
Update 2:
Issue is encountered in multiple Emacs versions by multiple users.
Update 3:
This doesn't appear to be an Emacs specific issue as I now get the occasional "Unable to save" popup window while attempting to save files in Sublime-text editor.
This can be a bug from emacs (M-x report-emacs-bug), some issue with your filesystem (I assume this is not the case because most likely you checked if problem happens with other editors), or some process in your local setup messing with your files.
For testing if the later is the case, you could try to eval this and then reproduce the problem:
(defadvice save-buffer (around find-shenanigan activate)
(condition-case ()
ad-do-it
(error
(shell-command (format "lsof -V %s" (buffer-file-name)) "*debug-issue*"))))
What this does is every time the save operation fails, it executes a command that takes a picture of the processes that have your file opened. If you see any process, you know who investigate. man lsof will help with the details.
Note: Does the problem happen also with emacs -Q?
EDIT: if you can use sudo without password (NOPASSWD in /etc/sudoers), replace "lsof" with "sudo lsof"
EDIT: I redirected the output of the lsof to a buffer named *debug-issue*; check that buffer if error.

I've downloaded an .exe file but it closes quickly as it opens

I am trying to open a downloaded .exe file but it closes as soon as it opens. Is there any possible way so that I can open it for a longer duration to read the content.
It's probably a console application rather than a GUI application. Use the command prompt to run the .exe.
Do the following...
Hold down your Windows key on your keyboard and then tap "R".
This will bring up the Run dialog. Type in "cmd" (without the quotes). Hit enter.
(this will work in all Windows versions - browsing the start menu/screen differs in each version)
If you saved the file to c:\downloads and it's called myFile.exe, type
C:
cd C:\Downloads
myFile.exe
Some of the steps are a bit redundant - if you know what you're doing in the command prompt then skip as needed (but then you probably wouldn't be posting this question). This will work even if you saved the file to D:\downloads.
Another example - if you saved the file to D:\folderA\Folder with a space\ and the file is called "my file with a space.exe" then type
D:
cd "D:\folderA\Folder with a space"
"my file with a space.exe"
If there is an issue (eg it's a 64-bit executable and you're on 32-bit Windows) then you may get a better error message at the command line.
There are so many reasons why the executable does not run. Here are some ways to check what is going wrong:
Is it your .exe? Do you known the "normal" behavior?
When you download it manually, it the result the same?
Do you download the .exe manually or via your application?
Do you see any problem in your Windows Event Viewer?
Is it the same result if you try to download the .exe via different browsers (IE, FF, ...)?
More details are welcome!
The nuget.exe file is not a console GUI application but rather a console package. Once you've downloaded it, you'll want to place it in a folder outside your Downloads folder. For example, C:\NuGet\nuget.exe - then set it as a PATH variable so that it's executable from anywhere.

Resources