The b is not “coming from nowhere”, it’s an indication that what you’ve got is a bytestring. Note that this indicator is a result of printing that output and is not part of the string itself.
I missed one more point.
My goal is to run the external Python script while clicking submit tab. Also, the input field is to accept password which will be 1st parameter in external script.
Thanks
Ahh - when posting code here, enclose each file’s contents between lines of three backtick - ` characters. That means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep the code properly formatted. (You can also do this with templates, error messages, html, and anything else you don’t want the forum to format or interpret.)
Try running your test.py script directly from the command line - does it work? Does it throw an exception?
If this only fails when being executed by your view, you might also want to capture stderr from the process and output that as well.
The print statement is adding the newline character. You can get rid of it using the end argument to print. But, if you correct the second issue, it shouldn’t be needed.
The output is coming back to your view as a bytestream. It’s in your view that you need to do the decode of the returned string from the script.
The issue isn’t in either your template or your script.
The issue is in using the run command and passing data through the command parameters and stdout. Those interfaces are, by definition, bytestreams. Python has no way of passing or receiving a Python String externally.
So it doesn’t matter what you do - what you send to your script is going to be a bytestream and what you get back is going to come back as a bytestream. It’s up to you to convert that into a string where needed.