mysql - How to find config error for Apache2 with Python on Ubuntu? -


i'm following digital ocean tutorial installing python on laptop's apache2 server. ubuntu 14.04 lts, python 3.4.3, mysql 14.14.

updating apache config seems straightforward:

<virtualhost *:80>     <directory /var/www/test>         options +execcgi         directoryindex index.py     </directory>     addhandler cgi-script .py     ...     documentroot /var/www/test     ... 

i can restart apache w/o issues.

the python test script @ /var/www/test/index.py seems straightforward. can run command line w/o problems, , chmod'd file 755 afterwards.

#!/usr/bin/python  # turn on debug mode. import cgitb cgitb.enable()  # print necessary headers. print("content-type: text/html") print()  # connect database. import pymysql conn = pymysql.connect(     db='example',     user='root',     passwd='your_root_mysql_password',     host='localhost') c = conn.cursor()  # insert example data. c.execute("insert numbers values (1, 'one!')") c.execute("insert numbers values (2, 'two!')") c.execute("insert numbers values (3, 'three!')") conn.commit()  # print contents of database. c.execute("select * numbers") print([(r[0], r[1]) r in c.fetchall()]) 

apache consistently bombing out "500", , access log doesn't provide further detail. know simple , there's nobody else in office expertise.

hints?

try one:

#!/usr/bin/python import os, logging   def customlogger(name):     logger = logging.getlogger(name)     logger.setlevel(logging.debug)     handler = logging.filehandler(os.path.join('/var/log/', name + '.log'), 'a')     logger.addhandler(handler)     return logger  error_logger = customlogger('errors_python')   # turn on debug mode. import cgitb cgitb.enable() try:     # print necessary headers.     print("content-type: text/html")     print()      # connect database.     import pymysql     conn = pymysql.connect(         db='example',         user='root',         passwd='your_root_mysql_password',         host='localhost')     c = conn.cursor()      # insert example data.     c.execute("insert numbers values (1, 'one!')")     c.execute("insert numbers values (2, 'two!')")     c.execute("insert numbers values (3, 'three!')")     conn.commit()      # print contents of database.     c.execute("select * numbers")     print([(r[0], r[1]) r in c.fetchall()]) except exception e:     error_logger.exception("error") 

open in browser , check /var/log/errors_python.log file. if file empty looks wrong apache2 configuration. in other scenario see errors.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -