Python脚本500错误

时间:2015-07-19 07:51:57

标签: python cgi

我目前正在尝试在我的网络服务器上运行一个相当基本的python脚本。当我尝试导入未安装在服务器上的东西时,我遇到了同样的错误

import json

我之前在服务器上运行了一个基本脚本,所以我知道python可以在它上面运行。该脚本在我的python IDE中工作没有任何问题但是当我把它放入我的服务器时,我得到500错误。关于为什么会发生这种情况的任何想法都将非常感激。我的webhost是JustHost.com,它使用CPanel。我确实联系了他们,他们说这是关于我的剧本的。

#! /usr/bin/python



import MySQLdb


db = MySQLdb.connect("localhost", "username","password","database")
CUR = db.cursor()

def get_password(username):
    sql = "select Password from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()[0]
    if result == None:
        return "User does not exist"
    else:
        return result[0]

def get_comment(username):
    sql = "select Comments from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User has not updated comment"
    else:
        return result[0]

def get_email(username):
    sql = "select Email from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User does not exist"
    else:
        return result[0]

def get_longitude(username):
    sql = "select Longitude from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User did not update location"
    else:
        return result[0]

def get_latitude(username):
    sql = "select Latitude from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User did not update location"
    else:
        return result[0]

def get_address(username):
    sql = "select Address from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User did not update email"
    else:
        return result[0]

def friends_list(username):
    sql = "select all friend from accepted_req where userLoggedIn=%s"
    CUR.execute(sql, [username])
    result=[]
    query = CUR.fetchall()
    if query == None:
        return "User has no friends"
    else:
        for friend in query:
            result.append(friend[0])

    return result

def markers_on_map(username):
    friendsList = friends_list(username)
    fullFriendsList = []
    for friend in friendsList:
        UserDictionary = {}
        UserDictionary["Username"] = friend
        UserDictionary["Comment"] = str(get_comment(friend))
        UserDictionary["Latitude"] = get_latitude(friend)
        UserDictionary["Longitiude"] = get_longitude(friend)
        fullFriendsList.append(UserDictionary)

    return fullFriendsList


print "Content-type: text/html\n\n"

print markers_on_map("brock")

1 个答案:

答案 0 :(得分:0)

我通过使它看起来完全符合我的webhost标准来修复它。新脚本现在看起来像这样

#! /usr/bin/python



import MySQLdb


db = MySQLdb.connect("localhost", "username","password","database")
CUR = db.cursor()

def get_password(username):
    sql = "select Password from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()[0]
    if result == None:
        return "User does not exist"
    else:
        return result[0]

def get_comment(username):
    sql = "select Comments from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User has not updated comment"
    else:
        return result[0]

def get_email(username):
    sql = "select Email from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User does not exist"
    else:
        return result[0]

def get_longitude(username):
    sql = "select Longitude from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User did not update location"
    else:
        return result[0]

def get_latitude(username):
    sql = "select Latitude from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User did not update location"
    else:
        return result[0]

def get_address(username):
    sql = "select Address from Users where Username=%s"
    CUR.execute(sql, [username])
    result = CUR.fetchone()
    if result == None:
        return "User did not update email"
    else:
        return result[0]

def friends_list(username):
    sql = "select all friend from accepted_req where userLoggedIn=%s"
    CUR.execute(sql, [username])
    result=[]
    query = CUR.fetchall()
    if query == None:
        return "User has no friends"
    else:
        for friend in query:
            result.append(friend[0])

    return result

def markers_on_map(username):
    friendsList = friends_list(username)
    fullFriendsList = []
    for friend in friendsList:
        UserDictionary123 = {}
        UserDictionary123["Username"] = friend
        UserDictionary123["Comment"] = str(get_comment(friend))
        UserDictionary123["Latitude"] = get_latitude(friend)
        UserDictionary123["Longitiude"] = get_longitude(friend)
        fullFriendsList.append(UserDictionary123)

    return fullFriendsList