OutOfMind
OutOfMind

Reputation: 924

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

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!

Upvotes: 6

Views: 11710

Answers (2)

Ramesh Raghavan
Ramesh Raghavan

Reputation: 149

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

import urllib.request as request

Upvotes: 6

OutOfMind
OutOfMind

Reputation: 924

Worked with following import:

import urllib.request

Upvotes: 6

Related Questions