Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 143715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:08:21+00:00 2026-05-11T08:08:21+00:00

The code #!/usr/bin/env python import MySQLdb print Content-Type: text/html print print <html><head><title>Books</title></head> print <body>

  • 0

The code

#!/usr/bin/env python  import MySQLdb  print 'Content-Type: text/html' print  print '<html><head><title>Books</title></head>' print '<body>' print '<h1>Books</h1>'  print '<ul>'  connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute(“SELECT name FROM books ORDER BY pub_date DESC LIMIT 10”)  for row in cursor.fetchall():     print '<li>%s</li>' % row[0]  print '</ul>'  print '</body></html>'  connection.close() 

I saved it as test.cgi to my web server. I run it by http://www.mysite.com/test.cgi unsuccessfully

Internal Server Error  The server encountered an internal error or misconfiguration and was unable to complete your request. 

How can you solve the problem?

[edit] after the first answer

  1. test.cgi is executable (I run $ chmod +x test.cgi)
  2. I use Apache.
  3. I have this in .bashrc export PATH=${PATH}:~/bin
  4. Python module MySQLdb is installed.
  5. The code does not have smart quotes.

[edit] after the second answer

you’re getting that error because you haven’t installed the MySQLdb module that Python needs to talk to a MySQL database

I installed MySQLdb to my system. The module works, since I can import them. However, I still get the same error whet I go to the http://www.[mysite].com/test.cgi.

[edit]

I am not sure about the questions

Are the connect() parameters correct? Is MySQL running on localhost at the default port?

I run MySQL on my server. Is the question about the connect() parameters relevant here?

Is the SELECT statement correct?

You mean whether I have my SQL statements such as SELECT statement correct? I have not used any SQL queries yet. Do I need them here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:08:21+00:00Added an answer on May 11, 2026 at 8:08 am

    Any number of issues can cause the error you are seeing:

    1. Is test.cgi executable (chmod 755) on the server?
    2. Is the directory in which you placed test.cgi designated as a ScriptAlias location or have the ExecCGI option enabled (or equivalent if you’re not using Apache)?
    3. Is python in the system PATH or in the PATH in the Web server’s startup environment?
    4. Is the MySQLdb Python library installed?
    5. Are the connect() parameters correct? Is MySQL running on localhost at the default port?
    6. Is the SELECT statement correct?

    If you’re sure that python is found (test using the simplest possible script or by logging into the Web server if you can and typing which python) then you can get much better debug output by adding the following to the top of your script just below the shebang:

    import cgitb cgitb.enable() 

    More details: http://docs.python.org/library/cgitb.html

    Additionally, if you have shell access to the Web server, try running python and just typing:

    >>> import MySQLdb 

    If the command returns with no error, you have your answer for #4 above. If an error is printed, you will need to get MySQLdb installed into the Web server’s Python installation.

    EDIT: Looking more closely at the top of your question, I see that the code was scraped from an illustrative example at the very beginning of the Django Book. As such, I might expand #5 above to include the caveat that, of course, the requisite database, tables, user, and permissions need to be set up on the MySQL installation available to the Web server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thank to everyone that helped here. I ended up figuring… May 11, 2026 at 9:30 pm
  • Editorial Team
    Editorial Team added an answer After some searching and trial and error, I developed the… May 11, 2026 at 9:30 pm
  • Editorial Team
    Editorial Team added an answer Sounds like you're using the pre-1.5 merge style and trying… May 11, 2026 at 9:30 pm

Related Questions

Greetings. I have written a little python script that calls MySQL in a subprocess.
Python 2.5.1 http://www.cgsecurity.org/wiki/After_Using_PhotoRec I've just run PhotoRec and the code given as a way
I've been writing writing a small pygtk application using glade to put together the
Questions : What does the kernel do if you stick a shell-script into the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.