#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep 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."

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep 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.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep 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.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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.

    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).

    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.


    Originally Posted by caroundw5h
    Thank you very much in advance for your replies.
    You're welcome.

    Dave - The Developers' Coach
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Canada
    Posts
    185
    Rep 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 05:59 PM.
    "In theory, there is no difference between theory and practice.
    But, in practice, there is."


IMN logo majestic logo threadwatch logo seochat tools logo