[cse491] query/post content

C. Titus Brown ctb at msu.edu
Mon Oct 12 16:33:02 PDT 2009


On Mon, Oct 12, 2009 at 07:29:55PM -0400, Joseph Christian Blossom wrote:
> So, I have two questions... first, I can't seem to get the urlparse library
> to import...the error when I run is:
> 
> File "webserve.py", line 25, in parse_request    query =
> urlparse.parse_qs(url)
> AttributeError: 'module' object has no attribute 'parse_qs'

Use cgi.parse_qs in Python 2.5, and urlparse.parse_qs in Python 2.6.

You can use the following magic to make it work in both:

try:
   from urlparse import parse_qs
except ImportError:
   from cgi import parse_qs

> And secondly, can we assume any particular order in which the query
> variables are coming in, along with post content? is it always  going to be:
> name, num, color, case?

Not to shout, but: USE parse_qs TO PARSE THESE STRINGS!  In which case
the order will not matter, because you will get a dictionary back.

--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the cse491-fall-2009 mailing list