view raw
Alex Lian Alex Lian - 8 months ago 31
Python Question

Import error when I try use "requests" module

I have a problem, when try to use requests lib

import requests

r = requests.get('')

After that, I got the following error

Traceback (most recent call last):
File "C:/Users/admin/Documents/alex/", line 3, in <module>
import requests
File "C:\Program Files\python3\lib\site-packages\requests\", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "C:\Program Files\python3\lib\site-packages\requests\packages\", line 27, in <module>
from . import urllib3
File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\", line 8, in <module>
from .connectionpool import (
File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\", line 35, in <module>
from .connection import (
File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\", line 44, in <module>
from .util.ssl_ import (
File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\util\", line 20, in <module>
from .retry import Retry
File "C:\Program Files\python3\lib\site-packages\requests\packages\urllib3\util\", 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.


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\ tries to import logging it imports wrong file. This may happen because
    • There is file called in the directory you are running your from. In this case, you will need to rename it so that logging from Python library is imported, not yours.
    • There is file called in one of directories from Python Path and it gets found before the 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\\, the wrong file is imported and you got to replace/rename it