The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
BaseHTTPServer and cgi.FieldStorage
Discuss BaseHTTPServer and cgi.FieldStorage in the Python Programming forum on Dev Shed. BaseHTTPServer and cgi.FieldStorage Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 5th, 2004, 03:24 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|

April 5th, 2004, 05:57 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
BaseHTTPServer does not handle CGI requests. Try using CGIHTTPServer instead.
Dave - The Developers' Coach
|

April 6th, 2004, 03:51 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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
|

April 7th, 2004, 06:49 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
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
|

April 10th, 2004, 01:50 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|

April 21st, 2004, 11:09 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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'))))
|

April 29th, 2004, 02:34 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
How do I parse this form? Is there some build in module that can parse such? I haven't come across anything.
|

April 30th, 2004, 09:15 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
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.
__________________
programming language development: www.netytan.com – Hula
|

May 1st, 2004, 01:50 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
And where can I find it?
Espen
|

May 1st, 2004, 08:24 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|