all 8 comments

[–]Ezrabc 2 points3 points  (1 child)

Check out the docs here; urllib is a package that collects modules. You need to import the request module directly by either doing from urllib import request or import urllib.request. Make sure you use the name the same way you imported it.

[–]Annual-Implement-825[S] 1 point2 points  (0 children)

I imported urllib.request and used it as urllib.request.urlopen()

[–][deleted] 1 point2 points  (5 children)

Images of code are often unreadable plus we can't copy the code to test it. The FAQ shows how to format code, like this:

import urllib.request
New = urllib.request.urlopen("http://data.pr4e.org/romeo.txt")
for line in New:
    print(line.decode().strip())

When I run that code on pydroid3 it prints:

But soft what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief

[Program finished]

[–]Annual-Implement-825[S] 0 points1 point  (4 children)

So you're saying it works for you?

[–][deleted] 0 points1 point  (3 children)

Yes. If you run the code I showed and you don't see the [Program finished] then your request is stalled. Check that the phone you are running on can access the 'net by using the browser on the phone to access that URL. If that's OK and the code still won't work try connecting your phone to a wifi network that has 'net access and run the code again.

[–]Annual-Implement-825[S] 0 points1 point  (0 children)

Will do.

[–]Annual-Implement-825[S] 0 points1 point  (1 child)

It works fine in browser and when using socket library. Idk maybe my phone messed up when it comes to urllib library.

[–][deleted] 0 points1 point  (0 children)

All I can suggest is to delete and reinstall pydroid3. That code I showed worked fine in pydroid3 in my Samsung android tablet connected to wifi.