Python脚本500错误
我目前正在尝试在我的web服务器上运行一个相当基本的python脚本。当我尝试导入服务器上没有安装的东西时,我遇到了同样的错误,比如Python脚本500错误,python,cgi,Python,Cgi,我目前正在尝试在我的web服务器上运行一个相当基本的python脚本。当我尝试导入服务器上没有安装的东西时,我遇到了同样的错误,比如 导入json 我以前在服务器上运行过一个基本脚本,所以我知道python可以在上面运行。该脚本在我的python IDE中运行时没有任何问题,但当我将其放入服务器时,我得到一个500错误。任何关于为什么会发生这种情况的想法都将不胜感激。我的网络主机是JustHost.com,它使用CPanel。我确实联系过他们,他们说是关于我的剧本 #! /usr/bin/pyt
导入json
我以前在服务器上运行过一个基本脚本,所以我知道python可以在上面运行。该脚本在我的python IDE中运行时没有任何问题,但当我将其放入服务器时,我得到一个500错误。任何关于为什么会发生这种情况的想法都将不胜感激。我的网络主机是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")
我修复了它,使它看起来完全完美的标准,我的网络主机。新脚本现在如下所示
#! /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
是否检查了从Web服务器启动脚本时是否设置了环境变量?根据MySQLdb的安装方式,
$PYTHONPATH
可能是您的朋友。。。