ImportError No module ngd-httpsclient

Using AWS Lambda to send push notifications to Pusher app in Python. When I install Pusher and all its dependencies to a directory and zip up to Lambda I run a simple test and get this error.

No module named ndg.httpsclient.ssl_peer_verification
Here is the code I'm trying to run.

```
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'})
```

I've seen several posts about this but installing the dependencies individually doesn't seem to be helping.

I've tried to post this on pusher github and have gotten to response. Banging my head on the wall 

Here is the stack trace

```
Traceback (most recent call last):
   File "pusherlambda.py", line 2, in <module> 
         pusher = Pusher(app_id=u'*****', key=*****', secret=u'****')
   File "/home/vagrant/Code/Lamdba/venv/lib/python2.7/site-packages/pusher/pusher.py", line 42, in __init__
         from pusher.requests import RequestsBackend
    File "/home/vagrant/Code/Lamdba/venv/lib/python2.7/site-packages/pusher/requests.py", line 12, in <module>
        import urllib3.contrib.pyopenssl
    File "/home/vagrant/Code/Lamdba/venv/lib/python2.7/site-packages/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
```


I could be wrong but I think this is a urllib3 issue not requests

On Thu, 24 Mar 2016 11:38 James Hoegerl notifications@github.com wrote:

> Using AWS Lambda to send push notifications to Pusher app in Python. When
> I install Pusher and all its dependencies to a directory and zip up to
> Lambda I run a simple test and get this error.
> 
> No module named ndg.httpsclient.ssl_peer_verification
> Here is the code I'm trying to run.
> 
> 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'})
> ```
> 
> I've seen several posts about this but installing the dependencies
> individually doesn't seem to be helping.
> 
> I've tried to post this on pusher github and have gotten to response.
> Banging my head on the wall
> 
> Here is the stack trace
> 
> Traceback (most recent call last):
> File "pusherlambda.py", line 2, in
> pusher = Pusher(app_id=u'_**', key=__', secret=u'_*_')
> File
> "/home/vagrant/Code/Lamdba/venv/lib/python2.7/site-packages/pusher/pusher.py",
> line 42, in *init_
> from pusher.requests import RequestsBackend
> File
> "/home/vagrant/Code/Lamdba/venv/lib/python2.7/site-packages/pusher/requests.py",
> line 12, in
> import urllib3.contrib.pyopenssl
> File
> "/home/vagrant/Code/Lamdba/venv/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py",
> line 49, in
> from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
> ImportError: No module named ndg.httpsclient.ssl_peer_verification
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub
> https://github.com/kennethreitz/requests/issues/3065


I'll head over and post there I guess. 


So could you provide more steps to reproduce this? Is it something like:
- create virtualenv
- pip install some things
- zip ... the virtualenv?
- upload to Lambda

Mostly, this traceback looks like you're using some kind of unvendored version of requests & urllib3 and I'm not sure how that's happening.

Are you installing ndg-httpsclient with Pusher and including that in your zip file?


Yah so basically I'll do just what you said.

```
virtualenv env
/env/bin/pip install pusher
```

<img width="1246" alt="screen shot 2016-03-23 at 9 47 32 pm" src="https://cloud.githubusercontent.com/assets/3597266/14007037/e224d230-f140-11e5-9c5d-cb335a295756.png">

Then i'll cd to site-packages and zip all of them together with my lambda script which is the code above and I'll test it and get that error.


Can you try not zipping everything together, but instead running in the virtual environment? I think your distribution of the environment is not working correctly: specifically, that the import path for `ndg-httpsclient` is getting munged.


Right so if I `cd env/lib/python2.7/site-packages/` and create and run a script called `lambda.py` with this code:

```
from pusher import Pusher
pusher = Pusher(app_id=u'***', key=u'***', secret=u'***')
pusher.trigger('testchannel', 'testevent', {u'some': u'data'})
```

I'll get the same stack trace.

```
> vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python lambda.py 
> Traceback (most recent call last):
>   File "lambda.py", line 3, in <module>
>     pusher = Pusher(app_id=u'***', key=u'***'', secret=u'***')
>   File "/home/vagrant/Code/Lamdba/env/lib/python2.7/site-packages/pusher/pusher.py", line 42, in __init__
>     from pusher.requests import RequestsBackend
>   File "/home/vagrant/Code/Lamdba/env/lib/python2.7/site-packages/pusher/requests.py", line 12, in <module>
>     import urllib3.contrib.pyopenssl
>   File "/home/vagrant/Code/Lamdba/env/lib/python2.7/site-packages/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
```


The code in pusher is quite confusing: they're trying to call into the urllib3 that is not bundled inside requests, which is for no adequately explainable reason exploding.

From your location on the filesystem, can you try the following Python one-liners and tell me what they return?

``` bash
python -c "import requests; print requests.__file__"
python -c "import urllib3; print urllib3.__file__"
python -c "import OpenSSL; print OpenSSL.__file__"
python -c "import ndg.httpsclient; print ndg.httpsclient.__file__"
```


```
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python -c "import requests; print requests.__file__"
requests/__init__.pyc
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python -c "import urllib3; print urllib3.__file__"
urllib3/__init__.pyc
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python -c "import OpenSSL; print OpenSSL.__file__"
OpenSSL/__init__.pyc
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python -c "import ndg.httpsclient; print ndg.httpsclient.__file__"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named ndg.httpsclient
```


Well that's bizarre. Does `pip freeze` show that ndg-httpsclient is installed?

@dstufft, any theories about this weirdness?


> vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ ../../../bin/pip freeze
> cffi==1.5.2
> cryptography==1.3.1
> enum34==1.1.2
> idna==2.1
> ipaddress==1.0.16
> ndg-httpsclient==0.4.0
> pusher==1.2.3
> pyasn1==0.1.9
> pycparser==2.14
> pyOpenSSL==16.0.0
> requests==2.9.1
> six==1.10.0
> urllib3==1.14


@sigmavirus24 Any luck with this?


What is in your site-packages directory? Mine looks like this:

```
ndg/
    httpsclient/
        __init__.py
        https.py
        ssl_context_util.py
        ssl_peer_verification.py
        # etc.
```


Also I just did `pip install requests[security]` and my `pip freeze` output looks like this:

```
cffi==1.5.2
cryptography==1.3.1
enum34==1.1.2
idna==2.1
ipaddress==1.0.16
ndg-httpsclient==0.4.0
pyasn1==0.1.9
pycparser==2.14
pyOpenSSL==16.0.0
requests==2.9.1
six==1.10.0
wheel==0.24.0
```

I'm having no problem import `ndg.httpsclient`.


I don't even see urllib3 on your pip freeze. I dont have wheel.

```
James-Hoegerls-MacBook-Pro:Music-Pub-Works jjh47$ ls -LR ../Lamdba/env/lib/python2.7/site-packages/ndg
httpsclient

../Lamdba/env/lib/python2.7/site-packages/ndg/httpsclient:
__init__.py         https.pyc           ssl_peer_verification.py    ssl_socket.pyc          test                utils.py
__init__.pyc            ssl_context_util.py     ssl_peer_verification.pyc   subj_alt_name.py        urllib2_build_opener.py     utils.pyc
https.py            ssl_context_util.pyc        ssl_socket.py           subj_alt_name.pyc       urllib2_build_opener.pyc

../Lamdba/env/lib/python2.7/site-packages/ndg/httpsclient/test:
README          __init__.pyc        scripts         test_https.pyc      test_urllib2.pyc    test_utils.pyc
__init__.py     pki         test_https.py       test_urllib2.py     test_utils.py

../Lamdba/env/lib/python2.7/site-packages/ndg/httpsclient/test/pki:
ca      localhost.crt   localhost.key

../Lamdba/env/lib/python2.7/site-packages/ndg/httpsclient/test/pki/ca:
08bd99c7.0  ade0138a.0

../Lamdba/env/lib/python2.7/site-packages/ndg/httpsclient/test/scripts:
openssl_https_server.sh

```


> I don't even see urllib3 on your pip freeze. I dont have wheel.

Because the issue seems to be in the fact that you can't import `ndg.httpsclient`. It has nothing to do with urllib3 being installed or anything.

I wonder if you could share the following:

```
$ pip --version
$ python -V
$ python -c 'import setuptools; setuptools.__version__'
```

I think this might be namespace package related (given that ndg-httpsclient is a namespace package) but that might be something of a red-herring. I'm not quite certain yet.


For what it's worth, my virtualenv pip version is 7.1.x and my python version is 2.7.11.


```
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ ../../../bin/pip --version
pip 8.1.1 from /home/vagrant/Code/Lamdba/env/local/lib/python2.7/site-packages (python 2.7)
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python -V
Python 2.7.8
vagrant@homestead:~/Code/Lamdba/env/lib/python2.7/site-packages$ python -c 'import setuptools; setuptools.__version__'
```

Last line gave no output.

Thank ya'll so much for the help btw. My first dive into Python.


I'm so dumb. I didn't use the `activate` command for virtual env and was running pip things with `env/bin/pip install` but I wasn't running programs with `env/bin/python lambda.py`

So that's working now. But it still wouldn't explain why Lambda would throw that error. Do I need to do something special in my python code to activate the python from my virtualenv?


@james-hoegerl I don't really know anything about lambda I'm afraid.


This isn't a requests issue. So I'm closing this.


Yah was just about to do that. Thanks for your help @sigmavirus24 @Lukasa. Sorry this ended up being so dumb. Heading to lambda forums.