UnicodeEncodeError caused by print when program runs from Popen - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: UnicodeEncodeError caused by print when program runs from Popen (/thread-36042.html) |
UnicodeEncodeError caused by print when program runs from Popen - SheeppOSU - Jan-12-2022 I am running a python program from another python program using subprocess.Popen, specifically like this subprocess.Popen(['python', self.path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) . I also tried specifying the encoding and errors parameters like so subprocess.Popen(['python', self.path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='utf-8') , which did not fix the error.Here's the entire traceback of the error: If I were to run the program from the command line with python, it runs just fine. However, as a subprocess, it seems to have trouble encoding certain characters. I would like some help figuring out the cause of the error and how I can fix it.
RE: UnicodeEncodeError caused by print when program runs from Popen - snippsat - Jan-12-2022 (Jan-12-2022, 07:46 AM)SheeppOSU Wrote: I am running a python program from another python program using subprocess.Popen,Why are doing this and not using the module/package way? When doing this you add an extra step and can get problem subprocess uses wrong encoding on Windows RE: UnicodeEncodeError caused by print when program runs from Popen - SheeppOSU - Jan-12-2022 I have a few bots which are being run on a separate device and I wanted to attempt in making a way to manage all of them remotely. Originally I used a shell script to simply run the bots and restart the device every so often, though this comes with some disadvantages. If I used a python program to start and manage the bots, it would be easy to create some kind of remote access. If there's a better way to achieve this I'd be happy to hear you out! RE: UnicodeEncodeError caused by print when program runs from Popen - snippsat - Jan-12-2022 Not going down the the module/package way. Here are two,both run the Python code that path point to from runpy import run_path run_path(r"G:\div_code\answer\html_test.py") # Other way exec(open(r"G:\div_code\answer\20_last.py").read()) RE: UnicodeEncodeError caused by print when program runs from Popen - SheeppOSU - Jan-12-2022 (Jan-12-2022, 10:28 PM)snippsat Wrote: Here are two,both run the Python code that path point toThanks, I'll look into these. RE: UnicodeEncodeError caused by print when program runs from Popen - SheeppOSU - Jan-13-2022 Thank you for the suggestions, however, neither of these options will work with what I'm trying to achieve. Though, since the error only incurs on windows, it will run on my raspberry pi just fine. |