我在 heroku 中部署了一个非常基本的 webscraper 来定期按下一个按钮,然后将一个链接复制到浏览器剪贴板,然后我使用以下方法将其存储在一个变量中:
text = pyclip.paste()
这在运行 Windows 10 的本地计算机上运行良好,但是当我将其部署到 heroku 时,出现以下错误:
2021-08-17T12:57:38.512015+00:00 app[worker.1]: text = pyclip.paste()
2021-08-17T12:57:38.512026+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pyclip/__init__.py", line
41, in paste
2021-08-17T12:57:38.512144+00:00 app[worker.1]: raise ClipboardSetupException("Could not setup clipboard").with_traceback(_CLIPBOARD_EXCEPTION_TB)
2021-08-17T12:57:38.512154+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pyclip/__init__.py", line
19, in <module>
2021-08-17T12:57:38.512316+00:00 app[worker.1]: DEFAULT_CLIPBOARD = detect_clipboard()
2021-08-17T12:57:38.512339+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pyclip/util.py", line 30,
in detect_clipboard
2021-08-17T12:57:38.512437+00:00 app[worker.1]: return XclipClipboard()
2021-08-17T12:57:38.512447+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pyclip/xclip_clip.py", line 29, in __init__
2021-08-17T12:57:38.512561+00:00 app[worker.1]: raise ClipboardSetupException(
2021-08-17T12:57:38.512595+00:00 app[worker.1]: pyclip.base.ClipboardSetupException: Could not setup clipboard
2021-08-17T12:57:38.656967+00:00 heroku[worker.1]: Process exited with status 1
2021-08-17T12:57:38.755984+00:00 heroku[worker.1]: State changed from up to crashed
我猜测功机确实没有剪贴板,然后webdriver可以将链接发送到该剪贴板,然后pyclip可以从中检索它。
有谁知道解决此问题的方法或在部署刮刀时如何设置和访问剪贴板?
编辑 1 我还安装了heroku-community/apt buildpack,然后在 Aptfile 中包含了copyq 以尝试在构建应用程序时设置剪贴板,但无济于事。有人认为 Docker 是个好主意吗?