"from pymongo import Connection" (to import mongo.connection using python) , got "500 Internal Server Error"

lindylin 发布于 2013/12/30 13:09
阅读 307
收藏 0

I created the /var/www/cgi-bin/test.py in my web server machine (Linux). The service of mongoDB "mongod" is running.

When I run the test.py locally, "./test.py", I could get the correct result.

But when I use the URL: http://xxxxxx.compute-1.amazonaws.com/cgi-bin/python_test/test.py to run the test.py, I will get the "500 Internal Server Error". 

If I remove the line "from pymongo import Connection", and use the URL above to access, I won't get the 500 Internal server error. So, it should be the problem when I import the pymongo.connection.

Is it the problem of any configuration issue? Thanks so much for your help

========== test.py ==============

import cgi
import sys

#import pymongo.connection
from pymongo import Connection
def main():
        print "Content-type: text/html\r\n\r\n"
        form = cgi.FieldStorage()
        name = form.getvalue('ServiceCode')
#       name = "abcddd"
#       con = Connection()
#       db = con.test
#       posts = db.post

#       print name
        if form.has_key("ServiceCode") and form["ServiceCode"].value!="":
                print"<h1>Hello", form["ServiceCode"].value,"</h1>"
                print"<h1>Error! Please enter first name. </h1>"