Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Web Server Gateway Interface
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example of calling an application=== A full example of a WSGI network server is outside the scope of this article. Below is a sketch of how one would call a WSGI application and retrieve its HTTP status line, response headers, and response body, as Python objects.<ref>{{cite web|url=https://www.youtube.com/watch?v=afnDANxsaYo |archive-url=https://ghostarchive.org/varchive/youtube/20211212/afnDANxsaYo| archive-date=2021-12-12 |url-status=live|title=Creating WSGI Middleware - Alan Christopher Thomas - Minted - PythonKC|date=2015-08-28|publisher=[[YouTube]]|access-date=2017-01-27}}{{cbignore}}</ref> Details of how to construct the <code>environ</code> dict have been omitted. <syntaxhighlight lang="python3"> from io import BytesIO def call_application(app, environ): status = None headers = None body = BytesIO() def start_response(rstatus, rheaders): nonlocal status, headers status, headers = rstatus, rheaders app_iter = app(environ, start_response) try: for data in app_iter: assert status is not None and headers is not None, \ "start_response() was not called" body.write(data) finally: if hasattr(app_iter, 'close'): app_iter.close() return status, headers, body.getvalue() environ = {...} # "environ" dict status, headers, body = call_application(app, environ) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)