Urllib import error

i am trying toaccess a webpage in command prompt by writing this code:

import urllib.request

fhand = urllib.request.urlopen(‘http://data.pr4e.org/romeo.txt’)
for line in fhand:

this code works well in python 3.10 but when i run same code in command prompt through Atom compiler i get a traceback call and an undesired index position program executes before traceback. please help me figure it out

Plesse don’t post images of text.

urllib tries to import from random, but you have shadowed the built-in random library by naming a file in your working directory ‘random.py’. Rename that file to something else, and in the future avoid using built-in names.

1 Like

thank you so much.stay blessed. people like you encourage me even more to continue learning in this field.thnx again.

1 Like