Jump to content

yakster8

Members
  • Posts

    1
  • Joined

  • Last visited

yakster8's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I would like to connect to a database using python without Django. My site is at http://a-catering.heliohost.org/cgi-bin/menuDatabaseMakerWeb.py. It takes a text file and creates a table from it. Whenever I run it, I get a 500 Internal Server Error. I believe I've narrowed the problem down to the actual connection (connection = MySQLdb.connect). I created the database and the user/password through cpanel. Please let me know if I missed something. Thank you. The code is below: #!/usr/bin/python # date: 4/19/12 # description: Database creator for catering website #The following imports the necessary modules import cgitb; cgitb.enable() import MySQLdb print "Content-Type: text/html" print print "Attempting to create DB" menuData = "/home/yakster8/public_html/menus.txt" menus = open(menuData) try: connection = MySQLdb.connect( host = "localhost", user = yakster8_root, passwd = password1234, db = yakster8_menus ) except: print "Failed..." print "Connected." cursor = connection.cursor() try: cursor.execute("""drop table menu""") except: pass sql = """CREATE TABLE menu (name text, category text, imageLocation text, dietaryConcerns text, """ # Create table cursor.execute(sql) connection.commit() for line in menus: line = line.strip() #removes leading and trailing white space lineParts = line.split('\t') sql = """ INSERT INTO menu VALUES (%s,%s,%s,%s) """ parameters = (lineParts[0:4]) #The following runs the SQL against the cursor cursor.execute(sql,parameters) connection.commit() print "Database created OK." Nevermind, I forgot quotes in the connection script. Problem solved.
×
×
  • Create New...