簡體   English   中英

在Web服務器上運行Python腳本

[英]Run Python Script on Web Server

我有一個Web服務器,我的cgi-bin在0755上,我的腳本return.py也是0755。

#!/usr/bin/perl

import cgi
import json


print "Content-type: text/plain\n\n";
print "testing...\n";

然后轉到網頁,我看到了測試……應該,但是當我將其中任何一個添加到腳本中時

form = cgi.FieldStorage()

param = form.getvalue("param")

if param:
    json.dumps({'success': True, 'message':  param })
else:
    json.dumps({'success': False, 'message':  'did not receive parameter' })

我收到一個500 Internal Server Error,我不確定為什么,我設置了正確的權限,並且python正在運行,因為當我不添加上面的內容時它可以工作嗎? 我上面的代碼有問題嗎? 還有什么可能導致此問題?

順便說一下,上面的代碼是因為我正在對此進行POST,並返回返回的值。 只是一個簡單的測試用例,但我無法使它正常工作?

我已經檢查了我可以檢查的清單,所有這些都有效https://encodable.com/internal_server_error/

我在這里先向您的幫助表示感謝。 :)

編輯

這是錯誤日志

[Tue Jun 23 01:35:38.661161 2015] [authz_core:error] [pid 874653] [client 173.34------:51484] AH01630: client denied by server configuration: /home/spencer/public_html/.htaccess
[Tue Jun 23 01:35:38.426745 2015] [access_compat:error] [pid 874653] [client 173.34-----:51484] AH01797: client denied by server configuration: /home/spencer/public_html/error_log

只是改變shebang,它應該工作

#!/usr/bin/perl
import cgi
import json
print "Content-type: text/plain\n\n";
print "testing...\n";

並假設您將其保存為test.py工作,然后在下面添加

#!/usr/bin/perl
import cgi
import json
print "Content-type: text/plain\n\n";
print "testing...\n";
form = cgi.FieldStorage()
param = form.getvalue("param")
if param:
    json.dumps({'success': True, 'message':  param })
else:
    json.dumps({'success': False, 'message':  'did not receive parameter' })

它給服務器錯誤

然后將shebang更改為

#!/usr/bin/python

它的工作原理....正確的射手和生活很輕松

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM