Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 5th, 2004, 03:24 PM
espenra espenra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 espenra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 5th, 2004, 05:57 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,205 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 17 h 39 m 53 sec
Reputation Power: 262
BaseHTTPServer does not handle CGI requests. Try using CGIHTTPServer instead.

Dave - The Developers' Coach

Reply With Quote
  #3  
Old April 6th, 2004, 03:51 PM
espenra espenra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 espenra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old April 7th, 2004, 06:49 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,205 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 17 h 39 m 53 sec
Reputation Power: 262
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

Reply With Quote
  #5  
Old April 10th, 2004, 01:50 AM
espenra espenra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 espenra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #6  
Old April 21st, 2004, 11:09 AM
mberardi mberardi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 mberardi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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'))))

Reply With Quote
  #7  
Old April 29th, 2004, 02:34 PM
espenra espenra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 espenra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #8  
Old April 30th, 2004, 09:15 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 2 m 16 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #9  
Old May 1st, 2004, 01:50 AM
espenra espenra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 espenra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
And where can I find it?

Espen

Reply With Quote
  #10  
Old May 1st, 2004, 08:24 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 2 m 16 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > BaseHTTPServer and cgi.FieldStorage


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway