+ Reply to Thread
Results 1 to 5 of 5

Thread: python cgi cannot open file (dbm database)

  1. #1
    sam.delta is offline x10Hosting Member sam.delta is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    3

    python cgi cannot open file (dbm database)

    hi, when my python cgi scripts executes (which executes fine) i get a 505 internal server error.
    i tracked down the error to the following line:

    "usersdb = anydbm.open("databases/users.dbm", 'r')"

    which is where i try to open a file (database). the database does exist in that directory and has 777 permissions.

    any help would be apreciated, thanks
    sam

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: python cgi cannot open file (dbm database)

    Quote Originally Posted by sam.delta View Post
    hi, when my python cgi scripts executes (which executes fine) i get a 505 internal server error.
    A 505 error means the server doesn't support the HTTP version the client is using. Are you sure that's the correct number? Do you have a live test page?

    Quote Originally Posted by sam.delta View Post
    the database does exist in that directory
    Do you have "databases" as a subdirectory of "cgi-bin"? If you did, it's an odd location for it; the best place for a database file is outside the web folder hierarchy, so you don't have to take special steps to prevent users from accessing it via the web server. If not, that's why the line is failing. In any case, you should always implement error handling. Catch the exception that anydbm.open is throwing and log it (don't display it to every user, for that reveals too much information).

    Quote Originally Posted by sam.delta View Post
    and has 777 permissions.
    Making the file world writable is terribly insecure.
    Last edited by misson; 07-10-2010 at 06:00 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    sam.delta is offline x10Hosting Member sam.delta is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    3

    Re: python cgi cannot open file (dbm database)

    thanks for your reply.

    My website is all contained in a single folder (test) which is located inside public_html. inside my page's folder, there are html files , database folder and cgi folder (i dont use default cgi-bin folder). i do this to prevent installation procedures as im making too much changes to keep track of everything.

    i dont know if this is correct practice, and any comments/suggestions would be appreciated.

    My databases have 777 permissions so my CGI's could edit them. Again, if theres is a better way, i would appreciate help here too.

    i made a cgi script which creates a new dbm database in databases folder, executed it, and it succesfully created the database, ill try to open this new db as 'reading' to see what happens.

    I'm not a experienced web programmer, and im still learning alot about good practices and security. Again, i appreciate your help.

    Thanks alot
    Sam

    EDIT:
    The error code was 500, my bad.
    I succesfully opened the database created by a cgi script, so i guess i cannot open uploaded databases, even tho they have permissions.
    Last edited by sam.delta; 07-12-2010 at 05:11 PM.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: python cgi cannot open file (dbm database)

    Quote Originally Posted by sam.delta View Post
    My website is all contained in a single folder (test) which is located inside public_html. inside my page's folder, there are html files , database folder and cgi folder (i dont use default cgi-bin folder). i do this to prevent installation procedures as im making too much changes to keep track of everything.
    If this is still in development, you should do it on your own server; try XAMPP or WampServer. You'll have much greater control over every aspect, including the ability to use an interactive debugger (not all Python interpreters support this for CGI scripts, but some do). Use file synchronization software (some FTP clients support this) to upload whenever you're at a stable, publishable point. If you want to follow best practices, use a version control system, such as svn or git. There are a number of public VCS servers you can use to host your project. This way you don't need to worry about where the most up-to-date version of any file is.

    Other than that, use cPanel to park or create an add-on domain that's rooted in the subfolder (search the forums for tutorials). The cgi-bin directory is special, and cgi scripts won't necessarily work outside of it.

    The database files themselves shouldn't be in the web hierarchy. If you must place them there, configure Apache not to serve the files. Read the thread "_private folder?" for details.

    Quote Originally Posted by sam.delta View Post
    My databases have 777 permissions so my CGI's could edit them. Again, if theres is a better way, i would appreciate help here too.
    The web server should be configured to run CGI scripts with their owner's credentials, which should be the same as the owner for the database files, so making the DB files world writable (and readable) should be unnecessary.

    Quote Originally Posted by sam.delta View Post
    i made a cgi script which creates a new dbm database in databases folder, executed it, and it succesfully created the database, ill try to open this new db as 'reading' to see what happens.

    EDIT:
    The error code was 500, my bad.
    I succesfully opened the database created by a cgi script, so i guess i cannot open uploaded databases, even tho they have permissions.
    CGI scripts should be able to open files with the same owner. Compare the owner of the scripts, the uploaded DB files and the script DB files.

    Did you catch any errors and log them, to figure out exactly what was going wrong? Don't guess, figure it out, otherwise you'll likely be wrong.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    sam.delta is offline x10Hosting Member sam.delta is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    3

    Re: python cgi cannot open file (dbm database)

    Alright, thanks for pointing me into the right direction.

    ill setup an old linux box i use as a server to test the site and just upload stable versions to x10h.

    I tried the error log in cpanel, and it only showed the line of error, but not the actual error. ill try to catch exceptions in a bit.

    For checking ownership, i cannot seem to view owners of files in the cpannel's file manager nor using a FTP client, can i log in using SSH to the server?

    thanks
    Sam

+ Reply to Thread

Similar Threads

  1. Cant open my index php file
    By mentel in forum Free Hosting
    Replies: 6
    Last Post: 04-04-2010, 04:53 AM
  2. Open File Issue
    By e85andyou in forum Programming Help
    Replies: 2
    Last Post: 08-17-2009, 09:37 PM
  3. Problem on Python Class File
    By bryanda in forum Free Hosting
    Replies: 0
    Last Post: 06-30-2009, 09:44 AM
  4. How do I open a file and overwrite contents?
    By nlester in forum Programming Help
    Replies: 5
    Last Post: 05-04-2008, 02:21 PM
  5. Open the EXE file in flash player.
    By satheesh in forum Tutorials
    Replies: 0
    Last Post: 10-04-2007, 09:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers