Search code examples
pythonsyntax-error

AttributeError: partially initialized module 'urllib.request' has no attribute ' urlopen' (most likely due to a circular import)


I was learning about accessing data through url in python ....And I have written following code

import json   
import urllib.request as ur  
url= input('Enter site: ')  
print( 'Retrieving ', url)  
data = ur.urlopen(url).read()  
info = json.loads(data)  
tot = 0  
print ('Retrieved ', len(data), 'characters')  
print ('Count: ', len(info['comments']))  
for i in range(0, len(info['comments'])):  
   tot += int(info['comments'][i]['count'])  
print ('Sum ', tot)

And I was getting the following error

    data = ur.urlopen(url).read()
    AttributeError: partially initialized module 'urllib.request' has no attribute '
    urlopen' (most likely due to a circular import)

Can anyone help me?? Thank you in advance !!


Solution

  • I faced the same issue earlier & here is the fix.

    I used the name urlilib as my file name:

    image

    I changed my file name to some other words & it WORKED FOR ME! :)

    enter image description here

    Hope you find the answer to be simple & useful