147

I am trying to run my script but keep getting this error:

File ".\checkmypass.py", line 1, in <module>
  import requests 
line 3, in <module>
  response = requests.get(url) 
AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)

How can I fix it?

1
  • 2
    try to change your file name Commented Jul 31, 2023 at 17:11

2 Answers 2

309

This can happen when there's a local file with the same name as an imported module – Python sees the local file and thinks it's the module.

In my case, I had a file I created in the same folder called requests.py. So my code was actually importing that file and not the actual requests module you install with pip. Then I had another issue with a file I created called logging.py. I renamed both files and the issue was resolved.

Sign up to request clarification or add additional context in comments.

1 Comment

I feel so silly making this mistake many times
116

Make sure the name of the file is not the same as the module you are importing – this will make Python think there is a circular dependency.

Also check the URL and the package you are using. "Most likely due to a circular import" refers to a file (module) which has a dependency on something else and is trying to be imported while it's already been imported. Once it's correct, you should have something like this:

import requests

r = requests.get("http://google.com")       
print(r.status_code)

# 200

3 Comments

I used the code you gave above,but I'm getting the same error can you explain more elaborately.Thank you in advance.
you have a local file with the same name as the imported module, hence it tries to recursively import itself. just rename this file.
It can happen when you already have declared your list of file to load in the __all__ array in the __init__.py' file of your module. Modules names are already used so Python return an error

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.