3

I have a problem, when try to use requests lib

import requests

r = requests.get('http://www.python.org/')
print(r)

After that, I got the following error

Traceback (most recent call last):
  File "C:/Users/admin/Documents/alex/test.py", line 3, in <module>
    import requests
  File "C:\Program Files\python3\lib\site-packages\requests\__init__.py", line 53, in <module>
    from .packages.urllib3.contrib import pyopenssl
  File "C:\Program Files\python3\lib\site-packages\requests\packages\__init__.py", line 27, in <module>
    from . import urllib3
  File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\__init__.py", line 8, in <module>
    from .connectionpool import (
  File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 35, in <module>
    from .connection import (
  File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\connection.py", line 44, in <module>
    from .util.ssl_ import (
  File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\util\__init__.py", line 20, in <module>
    from .retry import Retry
  File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\util\retry.py", line 15, in <module>
    log = logging.getLogger(__name__)
AttributeError: module 'logging' has no attribute 'getLogger'

I do not understand why is it at all. Please, help me.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
Alex Lian
  • 47
  • 1
  • 1
  • 7

1 Answers1

4

Your problem is one of the following

  1. Your installation of Python is terribly broken
  2. When C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\util\retry.py tries to import logging it imports wrong file. This may happen because
    • There is file called logging.py in the directory you are running your test.py from. In this case, you will need to rename it so that logging from Python library is imported, not yours.
    • There is file called logging.py in one of directories from Python Path and it gets found before the logging.py the module actually needs

To check what logging gets imported, write the following simple program

import logging
import os.path

print os.path.abspath(logging.__file__)

Whatever is printed is path to your logging file. If it is not along the line of ...\Python\\Python36\\lib\\logging\\__init__.py, the wrong file is imported and you got to replace/rename it

Dmitry Torba
  • 3,004
  • 1
  • 14
  • 24