Python Forum

Full Version: 500 Internal Server error trying to run external Python script via HTML
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am running a very simple HTML script on IIS 10.0 using Brython to communicate with a Python script.

HTML:

<html>
<!-- Based on https://anvil.works/blog/python-in-the-browser-talk -->
<head>
	<script src="pages/scripts/libz/brython-3.7.5.min.js"></script>
</head>
<body onload="brython(1)">
    <script type="text/python" src="python_test.py"></script>
    <form>
	    <input id="name-box" placeholder="Enter your name">
	    <button id="greet-button">Say Hello</button>
    </form>
</body>
</html>
Python:
import document, alert
def greet(event):
	alert("Hello " + document["name-box"].value + "!")

document["greet-button"].bind("click", greet)
I added Python as FastCGI module in my module mappings in IIS, and I also installed wfastcgi and included the path to its .exe within the module mapping and restarted IIS.

I still have a 500 Internal Server error:

Quote:Error occurred while reading WSGI handler:

Traceback (most recent call last):
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 586, in get_wsgi_handler
raise Exception('WSGI_HANDLER env var must be set')
Exception: WSGI_HANDLER env var must be set


StdOut:

StdErr:

I am unsure as to what I may have missed or have one wrong. Any help appreciated.

Thanks
Ok it went now to a 502 Bad Gateway error, and in spite of doing everything I could find online to fix the problem, the 502 persists, and nothing happens

HTML:
<html>
<!-- Based on https://anvil.works/blog/python-in-the-browser-talk -->
<head>
	<script src="scripts/libz/brython-3.7.5.min.js"></script>
</head>
<body onload="brython(1)">
    <script type="text/python" src="scripts/python_test.py"></script>
    <form>
	    <input id="name-box" placeholder="Enter your name">
	    <button id="greet-button">Say Hello</button>
    </form>
</body>
</html>
Python:
try:
	import document, alert
	def greet(event):
		alert("Hello " + document["name-box"].value + "!")

	document["greet-button"].bind("click", greet)
except NameError:
	print("Name Error")
except:
	print("Some other kind of error")
I did the following as well:

1) Added C:\users\me\AppData\Roaming\Python\Python313 to "Path" environmental variable
2) Added C:\users\me\AppData\Roaming\Python\Python313\Scripts to "Path" environmental varialbe
3) Restarted laptop
4) pip install document
5) pip install alert
6) Made sure that IIS contains a module mapping to *.py to go to C:\Python313\python.exe as CgiModule and removed all restrictions
7) Restarted IIS
8) Python version is 3.1.3

At this point I am out of ideas and could really use help to get even this very simple program to work on IIS. Help appreciated.

Thanks
I got it to the point where it now throws trace errors when opening up a .py file after a 500 Internal Server Error, but I am no farther than I was before. I am floundering.

I followed these instructions: wfastcgi

I created module mappings to go to both C:\Python313\python.exe and to C:\users\me\AppData\Roaming\Python\Python313\Lib\site-packages\wfastcgi.py

This is now the result:

Quote:Error occurred while reading WSGI handler:

Traceback (most recent call last):
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "C:\Python313\Scripts\wfastcgi.exe" could not be imported: Traceback (most recent call last):
File "C:\Python313\Lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
ModuleNotFoundError: No module named 'C:\\Python313\\Scripts\\wfastcgi'



StdOut:

StdErr:
Please note that the package wfastcgi hasn't been updated in almost 8 years.