Wamp Server无法运行pyscreenshot和pyautogui

时间:2019-05-07 08:59:31

标签: python-3.x wamp64

我正在使用WampServer64设置在Windows 10上运行的服务器。它在网页上提供按钮,以获取服务器屏幕的屏幕截图以及pyscreenshots和pyautogui的其他操作(如下所示)。

我的python脚本在cmd本地环境中运行良好,但是当我从网站运行它们时,当脚本遇到pyscreenshot方法或pyautogui方法(例如pyscreenshot.grab())时,它们会停止运行 我搜索了WampServer和python之间的问题,但只看到了有关CGI的信息,这不是我的问题。无论如何我都尝试过,但是没有用

这是我的代码的逻辑方案:

<input type="button" value="Get Screenshot" onclick="GetScreenshot()" />
function GetScreenshot(){
    $.ajax({
        url:"handle_screenshots.php",
        type: "POST",
        data:{action:'start_screenshots'},
        success: function(result) {
            alert(result);
        }
    });
};
if ($_POST['action'] == 'start_screenshots') {
    $path = $_SESSION['path'];
    $duration = 1000;
    pclose(popen("start /B cmd /C py C:\\wamp64\\www\\RTS_WebApp\\python\\screenshot.py $duration \"$path\" >NUL 2>NUL", 'r'));
    echo "Screenshots started";
}
import pyscreenshot, datetime, time, sys, re, os

if __name__ == '__main__':
    duration = sys.argv[1]
    if ':' in duration:
        wordList = re.sub("[^\w]", " ", duration).split()
        if (len(wordList) == 3) :
            duration = int(wordList[0]) * 3600 + int(wordList[1]) * 60 + int(wordList[2])
    else:
        duration = int(duration)

    i = 1
    left = 140
    top = 70
    right = 900
    bottom = 550
    start_time = time.time()
    while duration > (time.time() - start_time):
        name = "img_{}.png".format(i)
        img = pyscreenshot.grab()
        img = img.crop((left, top, right, bottom))
        img = img.resize((img.size[0], img.size[1]))
        img.save("C:\\wamp64\\www\\RTS_WebApp\\static\\img\\current.png")
        i += 1

编辑:我刚刚尝试过XAMPP,它确实起作用,所以我猜想python和WAMP之间有问题

0 个答案:

没有答案