Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP/AJAX调用Python-403禁止_Javascript_Php_Python_Ajax_Cgi - Fatal编程技术网

Javascript PHP/AJAX调用Python-403禁止

Javascript PHP/AJAX调用Python-403禁止,javascript,php,python,ajax,cgi,Javascript,Php,Python,Ajax,Cgi,大家好,我在使用PHP或AJAX通过我的网站调用python脚本时遇到问题 我所有的东西,html、php、css和.py都在同一个文件夹中/var/www/html/ JS: Python: degaps1.py import cgi import cgitb; cgitb.enable() print "Content-Type: text/html" print "" arguments = cgi.FieldStorage() print "test" 当我使用不带“./”的“url”

大家好,我在使用PHP或AJAX通过我的网站调用python脚本时遇到问题

我所有的东西,html、php、css和.py都在同一个文件夹中/
var/www/html/

JS:

Python:

degaps1.py
import cgi
import cgitb; cgitb.enable()
print "Content-Type: text/html"
print ""
arguments = cgi.FieldStorage()
print "test"
当我使用不带“./”的“url”打印整个代码时,现在我在控制台中收到一条消息。。。403禁止。我能做些什么来修复它?。提前谢谢


如果我没有记错的话,警报中的输出应该是“test”。

您不能像这样随时调用脚本,最多只能从中获得文件的内容。你需要一个服务器来做。。。你知道的。。。服务器端的东西,比如处理请求


看一看。它是python的一个小型服务器,设置它不需要时间,一旦设置好,就可以通过Javascript调用脚本。您也可以寻找其他解决方案,但我记得当我需要使用Python而不是PHP时,Flask是我的救星

我终于成功了!。我在conf.modules.d/apache.conf和conf.d/vhost.conf上的配置都设置得很好,有正确的文件路径。。。但是主文件conf/httpd.conf的所有设置都是错误的,我把它们都改了,它终于成功了!:D

vhost.conf

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName test
  ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  ErrorLog /var/www/html/logs/errors.log
  CustomLog /var/www/html/logs/access.log combined
  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>
而ajax是:

$.ajax({
  type: 'POST',
  url: '../cgi-bin/file.py',
  data: {param: param},
  success: function(response){
    output = response;
    alert(output);
  }
});

The output is: alert >> Hello World!

可能存在一些双重性,但它现在可以工作了:D

您的服务器是否配置为运行CGI脚本?默认情况下,请求Python文件只会获取该文件的内容。见:
DocumentRoot "/var/www/html"

<IfModule prefork.c>
    StartServers        5
    MinSpareServers     20
    MaxSpareServers     40
    MaxRequestWorkers   256
    MaxConnectionsPerChild 5500
</IfModule>
Include conf.modules.d/*.conf
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
#!/usr/bin/python
print "Content-type: text/html\n\n";
print "Hello World.\n";
$.ajax({
  type: 'POST',
  url: '../cgi-bin/file.py',
  data: {param: param},
  success: function(response){
    output = response;
    alert(output);
  }
});

The output is: alert >> Hello World!