Python Forum

Full Version: requests module is not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi,
I pip installed requests module and added it to my pydev path in my eclipse project. But when i run the program, I get the following error. Please help !
import requests
r = requests.get( 'https://xkcd.com/' )
print( r )
Error:
Traceback (most recent call last): File "/Users/apple/eclipse-workspace/test_demo/test_package/sqlite_requests.py", line 28, in <module> import requests File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/urllib3/__init__.py", line 7, in <module> from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/urllib3/connectionpool.py", line 3, in <module> import logging File "/Users/apple/eclipse-workspace/test_demo/test_package/logging.py", line 8, in <module> logging.basicConfig( filename = 'sample.log' , level = logging.DEBUG, format = '%(asctime)s:%(name)s:%(message)s' ) AttributeError: partially initialized module 'logging' has no attribute 'basicConfig' (most likely due to a circular import)
You have a file "/Users/apple/eclipse-workspace/test_demo/test_package/logging.py". This file shadows the logging module from Standard Library. Remove/rename that file.
(Sep-10-2020, 02:36 PM)buran Wrote: [ -> ]You have a file "/Users/apple/eclipse-workspace/test_demo/test_package/logging.py". This file shadows the logging module from Standard Library. Remove/rename that file.

OMG ! You are a saviour. It works perfectly fine now. Could you please explain as to how this code was linked to a different file ? Because i read it on the net that having a different requests.py file might be a problem.But how this file created a problem?
https://docs.python.org/3/tutorial/modul...earch-path

python looks for modules/packages you try to import in different locations in particular order. it finds your logging.py and try to import it, but this result in error
now documentation states that
Quote:When a module named spam is imported, the interpreter first searches for a built-in module with that name.
logging is built-in module, so I am missing something in this case. maybe someone else will shed some light why this happens.