首页 > 解决方案 > 在服务器上找不到 Python 脚本

问题描述

我正在开发一个嵌入 Python 脚本的 Wordpress 插件。我已将 Python 脚本上传到我的服务器,起初我在要运行我的脚本的网页上收到一条错误消息,说“权限被拒绝”(我已将 stderr 重定向到 stdout 以使我能够看到错误消息)。当我添加执行权限时,我会收到一条“未找到”消息(通过 Filezilla 完成)。

我可以看到脚本在服务器上的正确文件夹中,并且显然是在权限错误时发现的。如何让我的插件找到 Python 文件?

这是插件中的相关PHP函数:

function embed_python( $attributes )
{
    $data = shortcode_atts(
        [
            'file' => 'hello.py'
        ],
        $attributes
    );

    $handle = popen( __DIR__ . '/' . $data['file'] . ' 2>&1', 'r' );
    $read = '';

    while ( ! feof( $handle ) )
    {
        $read .= fread( $handle, 2096 );
    }

    pclose( $handle );

    return $read;
}

标签: wordpressserverpermission-deniedfile-not-found

解决方案


原来它就像我使用的服务器(Loopia)一样简单,需要某个文件夹中的 Python 脚本才能找到/运行它,以及更改了几个设置,请参阅这个瑞典页面:https://support。 loopia.se/wiki/python/


推荐阅读