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:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old April 7th, 2004, 03:02 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 181 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 55 m 34 sec
Reputation Power: 0
abyss web server and python

I recently installed the abyss webserver to run and test my cgi scrips locally on my machine. I was wondering a couple of things as I am not used to cgi programming with python.

1) are ALL the dictionary methods supported by the fieldstorage class? because I have tried to use some and I get errors from cgitb that the class has no attribute of that name. ex: iteritems(), items, and some others. I am wondering if i am coding my script wrong. For example should i first do the processing of the form and then decalare the "content-type: "text/html" header. would that help. or are not all dictionary methods supported? Thank you

2)I've installed my form_processing script not in the cgi-bin and it is still called when a user does the required action. Is it mandatory that the script be in the cgi-bin or as long as it is accessed its fine. For example when i upload it to my hosting company will their be incompatibilities? forgive me if these questions are stupid.

Thank you for you time.
__________________
"In theory, there is no difference between theory and practice.
But, in practice, there is."


Reply With Quote
  #2  
Old April 7th, 2004, 04:21 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,193 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 12 h 59 m 24 sec
Reputation Power: 252
1) The FieldStorage class supports some of the dictionary methods, but not all of them. As you point out, it does not support the items and iterxxx methods.

As for when to print the headers, my preference is to do the processing first, then print the headers and the result at the end. This allows me to change the headers if there is an error in processing the page. However this is a personal preference, and printing the headers first is perfectly OK.

2) I am not familar with the abyss web server, but in general web servers have some way of specifying which directories to use for CGI. Apache uses a configuration file, while (I think) M$ servers have registry entries edited through a GUI management interface. Some servers also let you specfy what file extensions to treat as CGI. It should all be covered in the docs for your server. It is unusual to allow ALL directories to be used for CGI, since it is a big security risk - if you had a file upload page, then someone could upload a malicious program and run it on the server.

You are right that using a convention different from the target host is asking for trouble. Find out what your host server expects and stick to that. Also find out where Python is installed on the server and make sure that the #! line at the start of your scripts use that - this also varies from system to system, and can be a major headache.

When starting on a new server I usually start with a simple test script:

Code:
#!/usr/local/bin/python
import cgi
cgi.test()


This displays all the fields and environment variables passed to the script, and this reassures me everything is set up correctly to run CGI, and that Python is installed where I expect. If the server is a UNIX-ish system, don't forget to set the file as executable.

Dave - The Developers' Coach

Reply With Quote
  #3  
Old April 7th, 2004, 07:19 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 181 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 55 m 34 sec
Reputation Power: 0
Thanks very much for your reply coach. I'm irritated that the cgi module doesn't support all the dictionry methods. but thanks again.

Reply With Quote
  #4  
Old April 7th, 2004, 08:22 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 181 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 55 m 34 sec
Reputation Power: 0
Instead of starting a new thread i'd thought i'd continue on here:

first of all a couple questions:

I want to have an email dispatched to a web email address every time a user fills out one of my forms. is there code to do this other than the mailto: beacuse that one starts up my browser's email. is there code that will send it to the public email i want and display the contents of the form to me

2)I know this is silly, but how many ppl can access my page at a time. I mean is it possible that someone tries to access it and they are not able to. or is this not possible due to the client server architecture of the internet.

3)if multiple users access my site and fill out the forms. assuming i have the data saved to a file, will that file be written over each time like python tends to do, or will it create a file for each difffeernt form input based on their ip? if it does write over the files contents is there a way to avoid this in python?

Thank you very much in advance for your replies.

Reply With Quote
  #5  
Old April 8th, 2004, 06:06 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,193 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 12 h 59 m 24 sec
Reputation Power: 252
Quote:
Originally Posted by caroundw5h
I want to have an email dispatched to a web email address every time a user fills out one of my forms. is there code to do this other than the mailto: beacuse that one starts up my browser's email. is there code that will send it to the public email i want and display the contents of the form to me


Take a look at smtplib in the Python docs. This can be used to contact an SMTP mail server and send an email. If your site is hosted on a unix-ish system then it will probably have an SMTP server running locally, and you could use the example in the docs directly. Contact your service provider and ask. Some providers have strict limits on how much email you can send, to prevent spammers using them.

Quote:
Originally Posted by caroundw5h
2)I know this is silly, but how many ppl can access my page at a time. I mean is it possible that someone tries to access it and they are not able to. or is this not possible due to the client server architecture of the internet.


The upper limit will depend on a lot of factors, such as the speed of the server and how long each request takes to service. If requests are coming in faster than they can be processed then eventually something has to give and the server will block requests by returning a 'server unavailable' HTTP response code (503).

Quote:
Originally Posted by caroundw5h
3)if multiple users access my site and fill out the forms. assuming i have the data saved to a file, will that file be written over each time like python tends to do, or will it create a file for each difffeernt form input based on their ip? if it does write over the files contents is there a way to avoid this in python?


The files will be saved out in whatever filename you specify in the code. If you give them all the same name then they will be overwritten. If you want them to have unique names then you will have to create the names yourself.

Do you need the data to be held long term, or just for the duration of the request? If it is only for the current request then you don't need to save it to disk at all - just keep the data in memory. If it is for longer term then you need to think about how your system is going to match up the data with the right user. Using IP address is dodgy, since many dial-up services assign a new IP address every time a user dials in.


Quote:
Originally Posted by caroundw5h
Thank you very much in advance for your replies.


You're welcome.

Dave - The Developers' Coach

Reply With Quote
  #6  
Old April 8th, 2004, 04:56 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 181 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 55 m 34 sec
Reputation Power: 0
Thank you coach dave. I have some more questions to fire at you. if thats okay. if not let me know.
1) i have the following code
Code:
Phone:<br/>
<input type="text" name="area_code" size="3"> -
<input type ="text"name="p_prefix" size="3"> -
<input type="text" name="p_suffix" size="3">
<p/>


assuming that form has alreadby been takien care of with the cgi.fieldstorage class. when I try to access the p_prefix and p_suffix names and values python cgitb tells me there is nothing like that. however it reads area_code fine? What is that. do i have to only have 1 text area for the phone number ? is there anyway to circumvent that?

to add insult to inury the code
Code:
print form.keys()
prints out everything else but the p_prefix and p_suffix. is this an html problem or python. obviously python doesn't want to read them. Why have a cgi returned as a dictionary type if it won't be able to use all the dictionary methods on them. like values, iteritems etc?

Last edited by caroundw5h : April 8th, 2004 at 04:59 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > abyss web server and python


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 1 hosted by Hostway