python-3.x - 属性错误: 'module' object has no attribute 'packages'

标签 python-3.x unit-testing django-rest-framework python-requests

when running test i'm getting this error.
早些时候我使用 python-requests v2.2.1 。所以, 我已经升级了python-requestsv2.14.2但我仍然面临着同样的问题。
HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict): AttributeError: 'module' object has no attribute 'packages'
检查以下结果:

======================================================================
ERROR: rest_blog.tests.test_views (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib/python3.4/unittest/case.py", line 577, in run
    testMethod()
  File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
    raise exception
ImportError: Failed to import test module: rest_blog.tests.test_views
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
    __import__(name)
  File "/home/vamsi/PycharmProjects/ReminderToDo/rest_blog/tests/test_views.py", line 6, in <module>
    from rest_framework.test import force_authenticate
  File "/usr/local/lib/python3.4/dist-packages/rest_framework/test.py", line 30, in <module>
    class HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict):
AttributeError: 'module' object has no attribute 'packages'


----------------------------------------------------------------------

最佳答案

只需重新安装 requests 或升级 requests 即可解决问题。

pip install --upgrade requests

关于python-3.x - 属性错误: 'module' object has no attribute 'packages' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43932410/

相关文章:

python - 我们如何在循环中创建 selenium webdriver 对象并在循环结束后关闭窗口?

python - 如何在Python中访问嵌套函数的变量?

Python:日期更改的单元测试

python-3.x - 如何修复 "Celery is receiving tasks but while executing it stuck"

python - django-rest-auth 注册/验证电子邮件/不工作

Django Rest Framework - 注册后返回身份验证 token

python - 无法显示带有点击入口点的 Python 二进制 PEX 版本

具有自定义字符的 Python 3 OCR

reactjs - 模拟点击 React with Enzyme 不执行任何操作

java - lateinit 属性模拟对象尚未初始化