Many people advised me to start using WSGI to avoid unnecessary wrestling with code to be able to modify my web system code (because of the expired feature CGI) without using complicated WSGI.
So I am trying to use WSGI. After installing WSGI, I successfully tested my first simple function. However, to my surprise, the function ‘os.environment’ contains NO important keys such as SERVER_NAME, REQUEST_METHOD and QUERY_STRING. Why not?
My code at server contains:
#!C:/Program Files/Python/python.exe
from wsgiref.simple_server import make_server
def web_app(environment, start_response):
status = '200 OK'
headers = [('Content-type', 'text/html; charset=utf-8')]
start_response(status, headers)
import os
tblose = os.environ
srvnmx = tblose.get('SERVER_NAME')
if srvnmx == None:
srvnmx = '?'
rqsmth = tblose.get('REQUEST_METHOD')
if rqsmth == None:
rqsmth = '?'
rqsqry = tblose.get('QUERY_STRING')
if rqsqry == None:
rqsqry = '?'
wrk = str.encode(''.join(['Hello, I just created my <strong>first</strong> WSGI',
'<br>SESSIONNAME=', tblose['SESSIONNAME'],
'<br>SYSTEMDRIVE=', tblose['SYSTEMDRIVE'],
'<br>SYSTEMROOT', tblose['SYSTEMROOT'],
'<br>SERVER_NAME=', srvnmx,
'<br>REQUEST_METHOD=', rqsmth,
'<br>QUERY_STRING=', rqsqry]))
return [wrk]
with make_server('', 8000, web_app) as server:
print('\nServing on port 8000...')
print('\nVisit http:127.0.0.1:8000')
print('\nTo kill the server enter \'control + C\'.')
server.serve_forever()
My first browser in put is:
localhost:8000/server/pythonwsgi/xxx.py?aaa=111&bbb=222&ccc=333
Output on my browser contains:
Hello, I just created my first WSGI
SESSIONNAME=Console
SYSTEMDRIVE=C:
SYSTEMROOTC:\WINDOWS
SERVER_NAME=?
REQUEST_METHOD=?
QUERY_STRING=?
Help, what should I have anything wrong?