简体   繁体   English

Azure 无法运行 python 脚本

[英]Azure failing to run python script

I built a simple web app using Flask.我使用 Flask 构建了一个简单的 Web 应用程序。 What this does is basically take data from a form and sends a POST - which is then passed as a command line argument to the script using它所做的基本上是从表单中获取数据并发送 POST - 然后将其作为命令行参数传递给脚本使用

os.popen("python3 script.py " + postArgument).read()

The command is stored in a variable which is then passed to an element in a new page with the results.命令存储在一个变量中,然后将其传递给带有结果的新页面中的元素。

About the script: It runs the string in the POST through an API, gets some data, processes it, sends it to another API and finally prints the results (which are finally stored in the variable)关于脚本:它通过 API 运行 POST 中的字符串,获取一些数据,处理它,将其发送到另一个 API,最后打印结果(最终存储在变量中)

It works fine on a local server.它在本地服务器上运行良好。 But Azure fails to return anything.但是 Azure 没有返回任何东西。 The string is empty.字符串为空。

How do I get some terminal logs?我如何获得一些终端日志?

Is there a solution?有解决办法吗?

Per my experience, it seems that the issue was caused by the Python 3 (even for Python 2) interpreter called python on Azure, not python3 .根据我的经验,问题似乎是由 Azure 上名为python的 Python 3(即使对于 Python 2)解释器引起的,而不是python3

So if you had configured the Python 3 runtime environment for the Application settings on Azure portal as the figure below, please using python script.py instead of python3 script.py in your code.因此,如果您在 Azure 门户上为应用程序设置配置了 Python 3 运行时环境,如下图所示,请在您的代码中使用python script.py而不是python3 script.py

在此处输入图片说明

Or you also can use the absolute path of Python 3 on Azure WebApp D:\\Python34\\python instead of python3 in your code, as below.或者,您也可以在 Azure WebApp D:\\Python34\\python上使用 Python 3 的绝对路径,而不是在代码中使用python3 ,如下所示。

在此处输入图片说明

However, I also doubt the another possible issue for you besides the above case.但是,除了上述情况之外,我也怀疑您可能遇到的另一个问题。 You may use some python packages which be not install using pip on Azure.您可能会使用一些未在 Azure 上使用pip安装的 python 包。 If so, you need to refer to the section Troubleshooting - Package Installation of the Azure offical document for Python to resolve the possible issue.如果是这样,您需要参考Azure 官方文档的Python 的Troubleshooting - Package Installation部分来解决可能的问题。

Hope it helps.希望能帮助到你。 Any concern & update, please feel free to let me know.任何关注和更新,请随时让我知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM