ImportError: cannot import name certs

When using Requests in a very basic function, it won't even start as it can't load "certs"

```
import requests
import django.utils.simplejson as json

def getFeed(user_id):
  jsonURL = "https://feed.whatever.net/json"
  resp = requests.get(jsonURL)
  result = json.load(r.json())

  import pdb; pdb.set_trace()
  return result
```

I get 

```
File "/home/vagrant/dev/python/team-calendar/team_calendar/calendar/json.py", line 1, in <module>
    import requests
  File "/home/vagrant/.virtualenvs/teamcalendar/local/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/home/vagrant/.virtualenvs/teamcalendar/local/lib/python2.7/site-packages/requests/utils.py", line 24, in <module>
    from . import certs
ImportError: cannot import name certs
```


What version of requests are you using and where did you install it from?


There's no need to answer that: this is another manifestation of #2026. =)


@sigmavirus24 @Lukasa I'm using 2.2.1 from pypi...

I saw in #2026 that it was "fixed" by installing 2.2.1 from pypi, but mine IS a normal, vanilla version...


Really? Can you tell me what the **version** string in `/home/vagrant/.virtualenvs/teamcalendar/local/lib/python2.7/site-packages/requests/__init__.py` says?


```
__title__ = 'requests'
__version__ = '2.2.1'
__build__ = 0x020201
__author__ = 'Kenneth Reitz'
__license__ = 'Apache 2.0'
__copyright__ = 'Copyright 2014 Kenneth Reitz'
```


Did you do `pip install requests==2.2.1` or did you do `pip uninstall requests` and then `pip install requests`. I'm not sure if pip will remove the `pyc` files before installing a new version. It could be causing issues for you if you don't uninstall everything first.


That does look like 2.2.1 and it appears to be in the place the traceback is coming from. Why is that relative import failing?


Are you running this in ipython?  I noticed that I get the same error in ipython when importing requests and not in the standard python shell...


Hang on, I'm pretty sure this is a manifestation of #2026. Anyone still affected should update to 2.3.0, which ought to fix the problem. 


We started seeing this with 2.6.0 this morning in our CI (codeship), and only in the CI. All tests are failing for us now because of this.

```
[... snip lots of lines from the pytest/django unit test machinery ...]
File "/home/rof/.virtualenv/local/lib/python2.7/site-packages/requests/utils.py", line 25, in <module>
from . import certs
ImportError: cannot import name certs
```

Tests were passing just fine until they didn't. No idea what caused it yet, we haven't changed anything. :confused: 


@bochecha Nothing breaks without a change. _Something_ in your environment has changed. There are a few options:
1. Your code has changed. The Python import system is fragile and weirdly global. To work this out, do a binary search through your commits until you can find the breakage. The advantage of this is that it should be easily reproducible on more or less any system.
2. Your dependencies have changed. You appear to have pinned Requests: have you pinned everything else? Check whether any of your dependencies have pushed updates recently.
3. Your OS has changed. Do you control your OS image on Codeship?

Basically: code that is exactly the same doesn't just magically change. Given that the one thing you definitely _haven't_ changed is Requests, I think it's safe to say that Requests should not be the first place you look for problems. =D


> Nothing breaks without a change. Something in your environment has changed.

I know that. What I'm saying is that **we** didn't change anything. :wink:

I'm still tracking what actually happened.

> Your code has changed.

I've resubmitted a build that had previously passed, and it's now failing. Same code from the same git commit.

> Your dependencies have changed. You appear to have pinned Requests: have you pinned everything else?

Almost everything is pinned. Very few isn't, and I'm going through them.

> Your OS has changed. Do you control your OS image on Codeship?

No we don't. This is what I'm currently looking at.

>  I think it's safe to say that Requests should not be the first place you look for problems. =D

Sure, I just found this ticket with the exact same symptoms, and a comment saying it is solved in 2.3.0, so I thought it was an interesting data point to report that it seems to have come back two years later.


So I do have one real question: where are you getting your deps from? PyPI, or from your OS?


> So I do have one real question: where are you getting your deps from? PyPI, or from your OS?

Most of them from PyPI, there is only one coming from a private github repo that we haven't modified since 2015.

---

Anyway, I finally found the culprit.

Now for the details...

Our deps are pinned, and it seems nobody ever updated them before I joined the project. So we have an old requests 2.6.0.

All the runtime deps are pinned, but not the development ones. One such unpinned dependency is pytest.

With pytest 2.9.2, the tests run just fine. With pytest 3.0.2, I reproduce the import problem on my workstation (so it's not just the CI). Upgrading to requests 2.6.1 fixes the `ImportError`.

That explains why things started failing this morning: the CI somehow updated pytest this morning in its virtualenv (it usually uses a cached version of the virtualenv).

 tl;dr: **It seems requests==2.6.0 doesn't work with pytest==3.0.2.** Leaving it here in case it can help someone else in the future.

/me goes and upgrades all the deps :wink: 


This issue is cropping up again for me more than 2 years later. requests is installed as a dependency of ec2-metadata globally on an Ubuntu 16.04 machine. When importing requests in a python shell it imports fine. When it is imported as part of a salt external pillar module it fails with an ImportError.
```
Traceback (most recent call last):
  File "/srv/salt/modules/pillar/my_module.py", line 9, in <module>
    import ec2_metadata
  File "/usr/local/lib/python2.7/dist-packages/ec2_metadata.py", line 4, in <module>
    import requests
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 25, in <module>
    from . import certs
ImportError: cannot import name certs
```
Here is the pip freeze:
```
root@saltmaster:~# pip freeze
aws-cfn-bootstrap==1.4
boto3==1.9.69
botocore==1.12.69
cached-property==1.5.1
cffi==1.5.2
chardet==2.3.0
cryptography==1.2.3
docutils==0.14
ec2-metadata==1.8.0
enum34==1.1.2
futures==3.0.5
gitdb==0.6.4
GitPython==1.0.1
idna==2.0
ipaddress==1.0.16
Jinja2==2.8
jmespath==0.9.3
lockfile==0.12.2
Mako==1.0.3
MarkupSafe==0.23
msgpack-python==0.4.6
ndg-httpsclient==0.4.0
ply==3.7
pyasn1==0.1.9
pycparser==2.14
pycrypto==2.6.1
pycurl==7.43.0
pygit2==0.24.0
PyMySQL==0.7.2
pyOpenSSL==0.15.1
pystache==0.5.4
python-apt==1.1.0b1+ubuntu0.16.4.2
python-daemon==1.6.1
python-dateutil==2.4.2
python-systemd==231
PyYAML==3.11
pyzmq==15.2.0
redis==2.10.5
requests==2.9.1
s3transfer==0.1.13
salt==2016.3.8
six==1.10.0
smmap==0.9.0
tornado==4.2.1
urllib3==1.24.1
```
This is running within salt 2016.3.8+ds-1 installed through the official salt apt repo
```
deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main
```
And Python version:
```
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
```
I realize that this seems more like a bug with salt but thought I'd ask here in case anyone had any idea.

requests 2.9 is not supported any longer

Got the same issue with version `requests==2.19.1` on Heroku.
Any ideas what can go wrong there? Locally on Ubuntu 18 works well.