2015-07-19 110 views
-1

我目前正試圖在我的web服務器上運行一個相當基本的python腳本。當我嘗試導入的東西,是不是安裝在服務器上,以便像Python腳本500錯誤

import 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") 
+0

您是否檢查過從Web服務器啓動腳本時是否設置了環境變量?根據'MySQLdb'的安裝方式,'$ PYTHONPATH'可能是你的朋友...... – flaschbier

回答

0

我通過使它看起來完全符合我的網絡主機標準來修復它。新腳本現在看起來像這樣

#! /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