Search code examples
python-3.xattributeerror

Python: Attribute Error: 'module' object has no attribute 'request'


I extremely new to python and practicing Loading a dataset from a url.

When running the following code:

In [1]: myUrl = "http://aima.cs.berkeley.edu/data/iris.csv"
In [2]: urlRequest = urllib.request.Request(myUrl)

I get this error:

File "", line 1, in urlRequest = urllib.request.Request(myUrl)

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

1) I tried researching this error and attempted to use import urllib3 again and it imported fine. However when attempting the request I get that error...

2) I attempted to get "help" help("urllib3") in python 3.6.0 and got:

No Python documentation found for 'urllib3'. Use help() to get the interactive help utility. Use help(str) for help on the str class.

3) I searched Stackoverflow and saw a similar question; tried the suggestions and was not able to move past that line of code...

Am I doing something wrong here?

Thanks in advance for your time


Solution

  • From what I see "request" is not a package, meaning that you can't directly import classes from it.

    try :

    from urllib.request import Request
    myUrl = "http://aima.cs.berkeley.edu/data/iris.csv"
    urlRequest = Request(myUrl)