Python3 error : AttributeError: module 'urllib' has no attribute 'request'
Asked Answered
M

2

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!

Margret answered 25/11, 2021 at 17:42 Comment(3)
(a) Are you entirely sure you're using Python 3? (b) Do you have a file called urllib.py?Barhorst
(a) yes (b) no , import urllib.request worked for me, thanks!Margret
"import urllib.request worked for me"—that seems unlikely considering the error you were getting. Voting to close as "not reproducible".Barhorst
M
6

Worked with following import:

import urllib.request
Margret answered 25/11, 2021 at 17:43 Comment(0)
L
6

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

import urllib.request as request
Lully answered 25/11, 2021 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.