尝试从HTML(Ajax)运行Python脚本时出错

时间:2019-01-10 16:28:44

标签: python html button server-side

我是HTML的绝对入门者,我真的不知道自己在做什么。我有一个由github托管的网站,当我按下网站上的按钮时,我希望它在我的计算机上执行python脚本。到目前为止,这是我的代码:

<!DOCTYPE html>
<html>
  <head> 
   <h1>Press The Button To Run The Python Script</h1>   
  </head>
  <body>
    <input type="button" id='script' name="scriptbutton" value=" Run Script " onclick="goPython()">

    <script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

    <script>
        function goPython(){
            $.ajax({
              url: "MYSCRIPT.py",
             context: document.body
            }).done(function() {
             alert('finished python script');;
            });
        }
    </script>
  </body>
</html> 

这是我遇到的错误:

Access to XMLHttpRequest at 'file:///C:/Users/Mihkel/Desktop/MYSCRIPT.py' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

MYSCRIPT.py和test.html文件位于同一目录中。我是否需要修改python脚本以使其正常运行?在我看来,这个错误似乎是权限错误,是真的吗?

0 个答案:

没有答案