doumeng1089 2017-07-24 20:33
浏览 135

PHP / AJAX调用Python - 403 Forbidden

Hello guys I'm having problems with calling a python script through my website, either using PHP or AJAX

All my stuff, html, php, css and .py are in the same folder /var/www/html/

JS:

document.getElementById('print').onclick = function(){Print()};
function Print() {
var param = 'zya';
  $.ajax({
    type: 'POST',
    url: '../degaps1.py',
    data: {param: param},
    success: function(response){
      output = response;
      alert(output);
    }
  });

Python:

degaps1.py
import cgi
import cgitb; cgitb.enable()
print "Content-Type: text/html"
print ""
arguments = cgi.FieldStorage()
print "test"

When I was using the "url" without "../" it was printing the entire code, now I get a message in the console... 403 Forbidden. What can I do to fix it?. Thanks in advance!

If I'm not wrong, the output in the alert should be "test".

  • 写回答

2条回答 默认 最新

  • douyi7055 2017-07-24 21:14
    关注

    You can't just call scripts on the go like this, at most what you can get from this is just the content of the file. You need a server to do... you know... server side stuff like handling requests.

    Have a look at Flask . It's a small server for python, it takes no time to set it up and once you set it up you can call your scripts via Javascript. You can also look for other solutions but I remember when I needed to use Python instead of PHP, Flask was my savior!

    评论

报告相同问题?

悬赏问题

  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。