繁体   English   中英

Python Pusher AWS Lambda

[英]Python Pusher AWS Lambda

使用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

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

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

 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 

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

这听起来可能很愚蠢,但不要命名您的局部变量pusher。 在lambda函数中,变量的绑定是在执行的后期,在您可能不期望的范围内进行的。

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

将一个空的__init__.py文件添加到ndg目录ndg此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM