google-code-export / django-hotclub

Automatically exported from code.google.com/p/django-hotclub
MIT License
0 stars 0 forks source link

Remove the WSGI stdout workaround #177

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. configure apache with python and mod_wsgi
2. start apache
3. connect to a url which invokes the wsgi bridge to pinax
4. see exception about writing to stdout

What is the expected output? What do you see instead?

It should throw an exception

What version of the product are you using? On what operating system?

The DC branch of pinax, but it uses the most current code from geopy.

Please provide any additional information below.

geopy/geocoders.py file uses "print" statement to complain about missing
imports (e.g. BeautifulSoup) but also status about parsing. The WSGI spec
says you can't send output to stdout, so this output breaks mod_wsgi.

Those outputs can be changed to python logging.warning() and logging.info()
messages which restores wsgi functionality. 

I've submitted a patch to the author on this and if he accepts it, Pinax
may have to change its reference to this external library. 

Original issue reported on code.google.com by Chris.Sh...@gmail.com on 4 Feb 2009 at 9:55

GoogleCodeExporter commented 9 years ago
There is a current implemented workaround in Pinax, see
pinax/projects/complete_project/deploy/complete_project.wsgi
{{{
# redirect sys.stdout to sys.stderr for bad libraries like geopy that uses
# print statements for optional import exceptions.
sys.stdout = sys.stderr
}}}

Original comment by ingenier...@gmail.com on 4 Feb 2009 at 10:28

GoogleCodeExporter commented 9 years ago
The WSGI specification doesn't disallow using 'print' but mod_wsgi places 
restrictions on doing so to promote 
portable WSGI applications. Specifically, certain WSGI adapters such as those 
for CGI, use stdin/stdout to 
communicate with the server. Thus, using 'print' in that case will cause debug 
messages to get mixed up in 
response output.

Although reassigning sys.stdout to sys.stderr can be used in the WSGI script 
file for mod_wsgi, it is 
discouraged. The original package which is producing debug output, should be 
use sys.stderr explicitly and 
not sys.stdout implicitly.

Thus, package should use:

  print >> sys.stderr, "some debug"

That or use proper logging system.

Original comment by Graham.Dumpleton@gmail.com on 5 Feb 2009 at 3:05

GoogleCodeExporter commented 9 years ago
I am in agreement with Graham. The external library *should* be fixed. However, 
unfortunately we don't have 
direct access to it, but we could fork it. As ingenieroariel pointed out we do 
work around this by redirecting 
sys.stdout to sys.stderr which as pointed out is really discouraged and I am 
not happy with it.

One of the things we want to do before we hit a 1.0 is fix issues like this. 
However, the original report is 
incorrect in that if you are seeing the exception about not being allowed to 
write to sysout in mod_wsgi then 
*you* are doing something wrong. I am going to adjust the title to reflect the 
real issue here.

Original comment by bros...@gmail.com on 5 Feb 2009 at 3:29

GoogleCodeExporter commented 9 years ago

Original comment by bros...@gmail.com on 5 Feb 2009 at 3:30

GoogleCodeExporter commented 9 years ago

Original comment by jtau...@gmail.com on 16 Mar 2009 at 3:07