ImportError:无法导入名称'证书'

时间:2014-11-14 11:10:29

标签: python python-3.x python-requests importerror

我在过去2天内遇到此错误。这似乎是python请求库的一个问题,但我已经多次重新安装它而没有运气。

Traceback (most recent call last):
    File "project-src/bla-blah/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
    File "project-src\env\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    utility.execute()
    File "project-src\env\lib\site-packages\django\core\management\__init__.py", line 354, in execute
    django.setup()
    File "project-src\env\lib\site-packages\django\__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
    File "project-src\env\lib\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
    File "project-src\env\lib\site-packages\django\apps\config.py", line 112, in create
    mod = import_module(mod_path)
    File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
    File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
    File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
    File "<frozen importlib._bootstrap>", line 1129, in _exec
    File "<frozen importlib._bootstrap>", line 1471, in exec_module
    File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
    File "project-src\env\lib\site-packages\social\apps\django_app\__init__.py", line 14, in <module>
    from social.apps.django_app.utils import load_strategy
    File "project-src\env\lib\site-packages\social\apps\django_app\utils.py", line 12, in <module>
    from social.backends.utils import get_backend
    File "project-src\env\lib\site-packages\social\backends\utils.py", line 2, in <module>
    from social.backends.base import BaseAuth
    File "project-src\env\lib\site-packages\social\backends\base.py", line 1, in <module>
    from requests import request, ConnectionError
    File "project-src\env\lib\site-packages\requests\__init__.py", line 58, in <module>
    from . import utils
    File "project-src\env\lib\site-packages\requests\utils.py", line 24, in <module>
    from . import certs

    ImportError: cannot import name 'certs'

也许这是2天前Windows 7更新的问题,因为这是过去几天内唯一发生变化的事情。

顺便说一下,我正在使用带有virtualenv的python 3.4,PyCharm 3.4.1 IDE和Win7。

certs.py 中,有代码存在问题(最后一行):

try:
    from certifi import where
except ImportError:
    def where():
        """Return the preferred certificate bundle."""
        # vendored bundle inside Requests
        return os.path.join(os.path.dirname(__file__), 'cacert.pem')

3 个答案:

答案 0 :(得分:1)

如果您想知道这个问题发生了什么......我重新安装了操作系统,再次下载了git项目,重新配置了python virtualenv并且'神奇地'它工作了。所以我确定在某个地方有一个错过配置,但它不是请求库问题。

如果您遇到同样的问题,我建议您安装一个新环境。

答案 1 :(得分:1)

上周我的Mac(塞拉利昂)也遇到了同样的问题。此外,certs.py模块存在,这意味着问题与操作系统有某种关系,而与Python本身无关。在我的情况下,这是最大文件限制的问题,所以只需用ulimit 200000 200000

增加它

答案 2 :(得分:1)

这对我有用(重新安装请求库):

pip uninstall requests pip install requests