python cgi cannot open file (dbm database)

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by, Jul 10, 2010.

  1. New Member

    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 ="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
  2. misson

    misson Community Paragon Community Support

    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?

    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 is throwing and log it (don't display it to every user, for that reveals too much information).

    Making the file world writable is terribly insecure.
    Last edited: Jul 10, 2010
  3. New Member

    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

    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: Jul 12, 2010
  4. misson

    misson Community Paragon Community Support

    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.

    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.

    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.
  5. New Member

    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?


Share This Page