How to get python connect to database example to work?

  • Answered
You have en example in your support center entitled "How to use Python to connect to a database" and I do not understand how to get the example python file within it to run. I have placed the .py file in the cgi-bin folder as directed.

In one spot, it is stated that
"When viewing this page in our browser, we see:

Database version : 5.0.92-community-log"
but I can't view it in my browser. In fact, for any file in the cgi-bin folder I get an internal server error when I navigate to it.

I hope I am correct in actually navigating to the .py file as it looks as though it is supposed to act like an html file based on the print statements at the bottom.

I have tried changing the file extension to .cgi as suggested by some help sites, but that has not helped either.

Any suggestions on how to make it so that browsers execute the .py file and interpret the printed results as html would be greatly appreciated.

Also it seems odd that the python file should go in the cgi-bin folder if it is supposed to act like an html page. Suppose you wanted the .py file to be your index file. Would it recognize it as one?

Tim S.
Hi brenner, Thanks for posting your question. I'm more than happy to assist you today. I looked over your account and did not see the test script so I could troubleshoot it. Have you removed the script? Also, you'll need to create a database and user, then attach the user to the database. Here's an article explaining how to to that: Creating a Database in CPanel Also, once the script is uploaded to the cgi-bin, you'll need to change the file permissions to 0755. If you need further assistance please feel free to contact us. Thanks! Tim S