All,

I ran into another issue with HTTPRequest for POSTs with Content-type other
than 'application/x-www-form-urlencoded'.

If a POST whose content-type is not 'application/x-www-form-urlencoded'
comes in with parameters on the query string you'll get:
Traceback (most recent call last):
  File "WebKit\ThreadedAppServer.py", line 287, in threadloop
    rh.handleRequest()
  File "WebKit\ThreadedAppServer.py", line 526, in handleRequest
    transaction = self.server._app.dispatchRawRequest(dict, strmOut)
  File "WebKit\Application.py", line 348, in dispatchRawRequest
    return self.dispatchRequest(self.createRequestForDict(newRequestDict),
strmOut)
  File "WebKit\Application.py", line 871, in createRequestForDict
    return self._requestClass(dict=newRequestDict)
  File "WebKit\HTTPRequest.py", line 43, in __init__
    self._fields.parse_qs()
  File "WebUtils\FieldStorage.py", line 53, in parse_qs
    keys = self.keys()
  File "C:\Python\lib\cgi.py", line 592, in keys
    raise TypeError, "not indexable"
TypeError: not indexable

The problem is at the end of WebUtils.FieldStorage.parse_qs(), where the
code does:
                # Only append values that aren't already in the FieldStorage's keys;
                # This makes POSTed vars override vars on the query string
                keys = self.keys()
                for key, values in dict.items():
                        if key not in keys:
                                for value in values:
                                        
self.list.append(cgi.MiniFieldStorage(key,value))

The line keys = self.keys() won't' work in this case becuse cgi.FieldStorage
doesn't populate self.list if the content type is not
'application/x-www-form-urlencoded'. Seems to me like cgi.FieldStorage
should be setting self.list = [] instead of None, then this wouldn't be a
problem, but I don't know what the other implications of that would be. To
fix it in the WebUtils.FieldStorage code, however, the above code can be
changed to:

                # Only append values that aren't already in the FieldStorage's keys;
                # This makes POSTed vars override vars on the query string
                if not self.list:
                        self.list = []
                keys = self.keys()
                for key, values in dict.items():
                        if key not in keys:
                                for value in values:
                                        
self.list.append(cgi.MiniFieldStorage(key,value))

I'm also not sure about the fact that (as the comment indicates) POSTed
parameters hide query string parameters when the request has both. Seems
like you'd just want to add them along with the POSTED parameters. I guess
you could always go back to queryString() and parse them out yourself.

Regards,

Chris


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - 
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to