【问题标题】:Python Pusher AWS LambdaPython 推送器 AWS Lambda
【发布时间】:2016-07-09 15:05:51
【问题描述】:

使用 AWS Lambda 将推送通知发送到 Python 中的 Pusher 应用程序。当我将 Pusher 及其所有依赖项安装到一个目录并压缩到 Lambda 时,我运行了一个简单的测试并收到此错误。

No module named ndg.httpsclient.ssl_peer_verification

这是我要运行的代码。

from pusher import Pusher

pusher = Pusher(app_id=u'id', key=u'key', secret=u'secret')
def createPitchZip(context, event):
    pusher.trigger('testchannel', 'testevent', {u'some': u'data'})

我已经看过几篇关于此的帖子,但单独安装依赖项似乎没有帮助。

谢谢!

编辑

这是堆栈跟踪

No module named ndg.httpsclient.ssl_peer_verification: ImportError
Traceback (most recent call last):
  File "/var/task/lambda.py", line 5, in createPitchZip
    pusher = Pusher(app_id='***', key='***', secret='***')
  File "/var/task/pusher/pusher.py", line 42, in __init__
    from pusher.requests import RequestsBackend
  File "/var/task/pusher/requests.py", line 12, in <module>
    import urllib3.contrib.pyopenssl
  File "/var/task/urllib3/contrib/pyopenssl.py", line 49, in <module>
    from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
ImportError: No module named ndg.httpsclient.ssl_peer_verification

【问题讨论】:

    标签: python amazon-web-services lambda pusher


    【解决方案1】:

    我建议您使用virtualenv 来跟踪依赖关系。

    这是您可能需要执行的伪步骤:

     1. virtualenv env
     2. env/bin/pip install <your packages>
     3. cd env/lib/python2.7/site-packages; zip -r mylambda.zip *
     4. also zip your lambda handler 
    

    如果您正确安装了所有内容,那么压缩文件mylambda.zip 将包含您需要的所有内容。

    【讨论】:

    • 是的,我在 AWS docs vs pip install -t directory pusher 中看到了他的另一个选项,我会试一试并回复你。感谢您的建议。
    • 刚刚完成了你的过程(这比 pip install btw 容易得多),我仍然遇到同样的错误。我已经添加了回溯到我的原始帖子以进行更多说明。 Requests 包出了点问题。
    【解决方案2】:

    这可能听起来很傻,但不要命名你的局部变量 pusher。 lambda 函数中的变量绑定发生在后期,在其执行期间,并且在您可能不期望的范围内。

    我并不是说这是完整的答案,但请执行 import pusher 并更改为 myPusher = pusher.Pusher... 以查看错误消息是否更改。如果不是,那么问题出在其他地方。

    【讨论】:

    • 有趣。让我试一试。
    • 试一试。相同的 ImportError。不过会留下。好点。
    【解决方案3】:

    将空的__init__.py 文件添加到ndg 目录可解决此问题。

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 2016-09-22
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多