6

I am trying to run a script in python3 (tried with 3.7.4 and 3.8.0) which uses urllib.request and urllib.error.

I tried importing in the following ways:

import urllib

and

from urllib import request

but in both the above cases I get error:

AttributeError: module 'urllib' has no attribute 'request'

I haven't installed anything related to urllib as it comes with python3

Please suggest how should this be imported, thanks!

3
  • (a) Are you entirely sure you're using Python 3? (b) Do you have a file called urllib.py? Commented Nov 25, 2021 at 17:43
  • 1
    (a) yes (b) no , import urllib.request worked for me, thanks! Commented Nov 25, 2021 at 17:44
  • 2
    "import urllib.request worked for me"—that seems unlikely considering the error you were getting. Voting to close as "not reproducible". Commented Nov 25, 2021 at 17:45

2 Answers 2

6

Worked with following import:

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

Comments

6

Since urllib is a folder and request is a file inside urllib, you should use:

import urllib.request as request

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.