alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

WSGI spec regarding QUERY_STRING not in compliance #174

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From dragonfy...@gmail.com on February 04, 2011 22:50:31

What steps will reproduce the problem? 1. install python 2.6, eventlet

  1. startup web2py using eventlet (anyserver.py works for this)
  2. place a request with no post/get vars
  3. request fails with an obscure error about cgi.parse_qsl What is the expected output? What do you see instead? I expect to see the welcome app popup, when I visit the root of a fresh web2py. Instead, I get a ticket, and when I try to view that ticket, I get another ticket (for admin), and on and on.

Pulling the ticket apart, I see this is the traceback:

print pickle.load(open("127.0.0.1.2011-02-04.20-58-18.f866b95b-a7f4-4c98-9fc0-e8223242cd70"))['traceback'] Traceback (most recent call last): File "/opt/web2py/gluon/main.py", line 373, in wsgibase parse_get_post_vars(request, environ) File "/opt/web2py/gluon/main.py", line 242, in parse_get_post_vars dget = cgi.parse_qsl(request.env.query_string, keep_blank_values=1) File "/usr/lib/python2.6/cgi.py", line 192, in parse_qsl return urlparse.parse_qsl(qs, keep_blank_values, strict_parsing) File "/usr/lib/python2.6/urlparse.py", line 335, in parse_qsl pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] AttributeError: 'NoneType' object has no attribute 'split'

Which leads me here, after some time looking at why rocket works: http://www.python.org/dev/peps/pep-0333/#environ-variables as the only difference in what is passed (I put in print statements to see environ. Gasp, the horror!): QUERY_STRING The portion of the request URL that follows the "?", if any. May be empty or absent.

I believe that cgi.parse_qsl deals with None just fine (I think). But urlparse.parse_qsl certainly does not. And in 2.6, urlparse.parse_qsl is what cgi.parse_qsl is handed to directly (cgi version is also deprecated)

Now this means, any time you don't pass a parameter to the page, any WSGI server that doesn't include QUERY_STRING is going to die an obscure death. If you look at PEP-333, you'll see that QUERY_STRING doesn't have to be included, it's just included if there is a query string. So in this case, web2py doesn't handle that part of wsgi very well (IMHO). Those couple chars below fix it beautifully by the way, without preventing any kind of parameters from being passed through (tested by me at least). What version of the product are you using? On what operating system? 1.91.4 of web2py python 2.6 Please provide any additional information below. Easy fix.

This line in gluon.main (241 in ver 1.91.4): dget = cgi.parse_qsl(request.env.query_string, keep_blank_values=1)

needs a fix like this, in case request.env.query_string is none (or some similar fix if this is considered kludgy): dget = cgi.parse_qsl(request.env.query_string or '', keep_blank_values=1)

The above allows using any eventlet based wsgi server, and a handful of others (I looked at a few, only about half included query_string 100% of the time) to be used with web2py, eliminating the crash described above. Oh, and it takes 5 seconds to change. :)

Original issue: http://code.google.com/p/web2py/issues/detail?id=176

alfonsodg commented 10 years ago

From massimo....@gmail.com on February 05, 2011 20:44:52

Status: Fixed