pyppeteer(+ asyncio)在AWS Severless上无法正常播放

时间:2018-11-10 21:26:52

标签: amazon-web-services python-asyncio puppeteer

我正在尝试建立一个AWS Lambda处理程序,该处理程序涉及使用pyppeteer(node.js中无头Chrome的python端口)进行屏幕截图。

def getSavePath():
    path = "picture_{}.png".format(random.randint(100, 1000))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(._screenshot(path))
    print("Done taking screenshot...")

    return path

async def _screenshot(path):
    browser = await launch()
    page = await browser.newPage()
    await page.goto(URL, {"waitUntil": "networkidle0"})

    textBox = await page.querySelector('[name="section"]')
    submitButton = await page.querySelector('#submit')
    canvas = await page.querySelector("#canvas")

    await textBox.click({"clickCount": 3});
    await textBox.type(self.wkt)
    await submitButton.click()

    await canvas.screenshot({'path': path})
    await browser.close()

当我在本地运行此命令时,将截取屏幕截图,并正确返回路径。

当我在AWS Lambda上运行它时,我得到了:

    loop.run_until_complete(._screenshot(path))
  File "/var/task/asyncio/base_events.py", line 296, in run_until_complete
    future = tasks.async(future, loop=self)
  File "/var/task/asyncio/tasks.py", line 516, in async
    raise TypeError('A Future or coroutine is required')
TypeError: A Future or coroutine is required
/var/task/slash.py:50: RuntimeWarning: coroutine '_screenshot' was never awaited

有什么想法为什么会在本地而不是在Lambda上起作用?

我在本地和Lambda上都使用Python 3.6版。

0 个答案:

没有答案