473,688 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WSGI spec clarification regarding exceptions

I'm trying to figure out if there's any defined behaviour in PEP 333
for instances where an application returns an iterable as usual
without error, but that iterable's next() method eventually raises an
exception. Since any data theretofore returned by the iterable must be
assumed to have already been written to the client, thus making it
impossible to replace the response with a 500 error or somesuch, does
the gateway just absorb the exception and cut off the response there?
It seems like that's pretty much all it could do, but I'm wondering if
that's explicitly specified anywhere (I couldn't find anything about
that in the PEP).

May 9 '07 #1
2 1185
On May 10, 8:26 am, Adam Atlas <a...@atlas.stw rote:
I'm trying to figure out if there's any defined behaviour in PEP 333
for instances where an application returns an iterable as usual
without error, but that iterable's next() method eventually raises an
exception. Since any data theretofore returned by the iterable must be
assumed to have already been written to the client, thus making it
impossible to replace the response with a 500 error or somesuch, does
the gateway just absorb the exception and cut off the response there?
It seems like that's pretty much all it could do, but I'm wondering if
that's explicitly specified anywhere (I couldn't find anything about
that in the PEP).
Because the WSGI specification requires that a WSGI adapter for a web
server always explicitly perform a flush after each string yielded
from the iterator then simply cutting off the response at that point
is all one can do as the first time a flush is done any response
status and headers will also have to be written out.

Now depending on the web server being used, all the client may see is
the truncated page, or it might also see some form of error page
appended to it by the underlying web server. For example, in Apache,
if the WSGI adapter returns HTTP_INTERNAL_S ERVER_ERROR back to the
server, the server disregards whether anything has already been sent
and tries to generate a 500 error page. Since the response status and
headers have already been flushed though, the original status is
received by the client, but the Apache error page content is still
sent. Thus you might get output looking like:

Hello World!
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The server encountered an internal error or
misconfiguratio n and was unable to complete
your request.</p>
<p>Please contact the server administrator,
yo*@example.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apac he/2.2.2 (Unix) mod_wsgi/1.0-TRUNK Python/2.3.5 Server at
localhost Port 8002</address>
</body></html>

It is actually hard to know what to do here. There are ways one could
stop the appending of the error page content, but is returning just
the truncated page any better. At least the error page content in
there highlights an issue even if status wasn't 500, but then not
being 500, the page content could get cached.

This is where one wanders whether the WSGI way of always flushing is a
good idea. It may be better to always use buffering unless one
specifically knows that one wants to do streaming of data where size
could be large or take some time to produce.

Anyway, for WSGI matters, you are probably better off bringing them up
on the Python WEB-SIG list.

http://www.python.org/community/sigs/current/web-sig/

Graham

May 10 '07 #2
On May 10, 12:07 pm, Graham Dumpleton <Graham.Dumple. ..@gmail.com>
wrote:
On May 10, 8:26 am, Adam Atlas <a...@atlas.stw rote:
I'm trying to figure out if there's any defined behaviour in PEP 333
for instances where an application returns an iterable as usual
without error, but that iterable's next() method eventually raises an
exception. Since any data theretofore returned by the iterable must be
assumed to have already been written to the client, thus making it
impossible to replace the response with a 500 error or somesuch, does
the gateway just absorb the exception and cut off the response there?
It seems like that's pretty much all it could do, but I'm wondering if
that's explicitly specified anywhere (I couldn't find anything about
that in the PEP).

Because the WSGI specification requires that a WSGI adapter for a web
server always explicitly perform a flush after each string yielded
from the iterator then simply cutting off the response at that point
is all one can do as the first time a flush is done any response
status and headers will also have to be written out.

Now depending on the web server being used, all the client may see is
the truncated page, or it might also see some form of error page
appended to it by the underlying web server. For example, in Apache,
if the WSGI adapter returns HTTP_INTERNAL_S ERVER_ERROR back to the
server, the server disregards whether anything has already been sent
and tries to generate a 500 error page. Since the response status and
headers have already been flushed though, the original status is
received by the client, but the Apache error page content is still
sent. Thus you might get output looking like:

Hello World!
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The server encountered an internal error or
misconfiguratio n and was unable to complete
your request.</p>
<p>Please contact the server administrator,
y...@example.co m and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apac he/2.2.2 (Unix) mod_wsgi/1.0-TRUNK Python/2.3.5 Server at
localhost Port 8002</address>
</body></html>

It is actually hard to know what to do here. There are ways one could
stop the appending of the error page content, but is returning just
the truncated page any better. At least the error page content in
there highlights an issue even if status wasn't 500, but then not
being 500, the page content could get cached.

This is where one wanders whether the WSGI way of always flushing is a
good idea. It may be better to always use buffering unless one
specifically knows that one wants to do streaming of data where size
could be large or take some time to produce.

Anyway, for WSGI matters, you are probably better off bringing them up
on the Python WEB-SIG list.

http://www.python.org/community/sigs/current/web-sig/
BTW, forgot to mention that one can always create a WSGI middleware
component that does buffering and which only sends the complete
response. If an error occurs while accumulating the response, then you
can return a 500 status and error page of your own making.

Graham

May 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1275
by: Thomas W | last post by:
Will there be a WSGI-server like BaseHTTPServer etc in the standard distro? I think that would increase the adoptation of the WSGI-standard. A new web-framework for python pops up every other week and more and more support WSGI. Why not focus on getting an optimized, production-grade fully documented WSGI-server into the distro? Right now the BaseHTTPServer seems to be usable for development and testing, not production environment. Perhaps...
2
1399
by: Ben Finney | last post by:
Howdy all, I'm trying to implement some new functionality for an existing PHP web application. Rather than writing a whole lot of stuff in PHP, and looking toward a future when more of the application can be rewritten more sanely, I'd like to write a Python program that generates the content and serves it up to the existing application via HTTP. The existing architecture is as expected:
1
1231
by: seberino | last post by:
I love idea of WSGI and hope it succeeds. It seems to be helpful for person tempted to write his own framework.....they can now just mix and match existing components with WSGI //instead//. I not sure what WSGI offers the web beginner. Aren't they still better off learning an existing web framework first before attacking WSGI?
11
1832
by: Gregory Piñero | last post by:
So I keep hearing more and more about this WSGI stuff, and honestly I still don't understand what it is exactly and how it differs from CGI in the fundamentals (Trying to research this on the web now) What I'm most confused about is how it affects me. I've been writing small CGI programs in Python for a while now whenever I have a need for a web program. Is CGI now considered "Bad"? I've just always found it easier to write something...
7
1819
by: Ben Finney | last post by:
Howdy all, I'm working on a web application that is starting to gain a lot of back-end code written in Python. However, all the current interface code is written in legacy PHP. I'd like to slowly introduce new features as Python WSGI programs. Is it possible to write a Python WSGI program that talks to a PHP program as its "back end"? Where can I find out how to do this, preferably with examples?
8
2306
by: Ron Garret | last post by:
The wsgiref module in Python 2.5 seems to be empty: $ python Python 2.5 (r25:51908, Mar 1 2007, 10:09:05) on darwin Type "help", "copyright", "credits" or "license" for more information. So... is wsgi considered ready for production use, or is it still on the bleeding edge? And if the former, which implementation should one use?
37
2562
by: Michele Simionato | last post by:
At work we are shopping for a Web framework, so I have been looking at the available options on the current market. In particular I have looked at Paste and Pylons and I have written my impressions here: http://www.phyast.pitt.edu/~micheles/python/yet-another-comparison-of-web-frameworks.html I do not speak too well of Pylons, so if you thing I am wrong feel free to correct me here ;)
9
3238
by: Tool69 | last post by:
Hi, Until now, I was running my own static site with Python, but I'm in need of dynamism. After reading some cgi tutorials, I saw Joe Gregorio's old article "Why so many Python web frameworks?" about wsgi apps and have a question about it. The code he gave works like a charm (I had to make a little change because SQLAlchemy has changed since), but how the hell can I serve static files (css, js, images, etc.) within an wsgi
4
2678
by: inhahe | last post by:
I'm sorry if this is off-topic, i couldn't find a mailing list OR forum for WSGI (and #wsgi wasn't very helpful). i played around with StringIO, and apparently if you write to a stringio the position gets set to the end of the write, so if you read from it again, without using seek, you won't read what comes next, you'll skip to the end of the write. and if you write without seeking to the end first, you'll overwrite part of the string...
0
8594
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5810
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2219
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1952
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.