|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
BaseHTTPServer and cgi.FieldStorage
How come that I "cant't" use cgi.FieldStorage when using BaseHTTPServer that act as a server.
I have put python script (small one) online at: http://polartech.no/gallery/oblig2.py As written in the source code as comments, the do_POST method is called, but cgi.FieldStorage() return an empty fieldstorage. The big question is, how can I get the form data? cgi.FieldStorage() doesn't help me here. Espen |
|
#2
|
|||
|
|||
|
BaseHTTPServer does not handle CGI requests. Try using CGIHTTPServer instead.
Dave - The Developers' Coach |
|
#3
|
|||
|
|||
|
I have replaced
class Handler(BaseHTTPServer.BaseHTTPRequestHandler): with this one class Handler(CGIHTTPServer.CGIHTTPRequestHandler): The replaced class header is located at: http://polartech.no/gallery/oblig3.py and it is still the same. Don't know what more to do, have searched through google thousands times now. Any1 with a solution? Espen |
|
#4
|
|||
|
|||
|
OK, I have looked at your code, and I see what the problem is.
You can't embed the CGI code in the server code like that. The whole point of CGIHTTPServer (and CGI in general) is that it executes separate scripts in designated directories and returns the output. Because you had overridden the do_POST method, the code to parse the form data was never called. Use the CGIHTTPRequestHandler unmodified, and put the CGI code as a separate script in a subdirectory called cgi-bin. Dave - The Developers' Coach |
|
#5
|
|||
|
|||
|
If I let the server redirect the post call to a cgi script in /cgi-bin/ how can I get the Base server to reach the form data that the cgi script had pulled from the form?
Espen |
|
#6
|
|||
|
|||
|
to do what you want use BaseHTTPServer
and get the form data with form = cgi.parse_qs(self.rfile.read(int(self.headers.getheader('Content-Length')))) |
|
#7
|
|||
|
|||
|
How do I parse this form? Is there some build in module that can parse such? I haven't come across anything.
|
|
#8
|
||||
|
||||
|
I'm assuming we're talking about the string returned when manually parsing posted form data - in which case i've gotta tell you it isn't easy!
If you check out my NET module, in params.py you'll find a full featured form parser including posted data and file uploading. Everything is highly commented so you should be able to follow the steps pretty easily. Hope this helps, Have fun! Mark. |
|
#9
|
|||
|
|||
|
And where can I find it?
Espen |
|
#10
|
||||
|
||||
|
Sorry, i forgot to post the link, my bad
. You can find the latest version of NET here:http://forums.devshed.com/t129666/s.html I havn't had much time to work on it lattly so not much has changed since then. Hope you find what your looking for. Netytan |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > BaseHTTPServer and cgi.FieldStorage |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|