from urllib2 import request - cannot import name request

25,965

Solution 1

Try using

from urllib2 import Request

instead of

from urllib2 import request

Check the official documentation

Solution 2

Using

import urllib;

and then

urllib.urllopen();

For Python 2.7 you do not need import request.

Solution 3

try using:

import urllib2

and use urllib2 to instead of urllib.request

looking at the document https://docs.python.org/2/library/urllib2.html#urllib2.urlopen may help more.

Solution 4

I am using Python 2.7 and encountered the same problem. I was able to solve it after using urllib3 instead of urllib or urllib2.

Here's an example screenshot of using urllib3 working in Python 2.7: jupyter_Screenshot_for_urllib3

Share:
25,965
Niels Gorsel
Author by

Niels Gorsel

Updated on March 23, 2020

Comments

  • Niels Gorsel
    Niels Gorsel about 4 years

    So i am trying to write a program and i need the module named requests for this, since i am using python version 2.7.9.

    i thought using the code:

    from urllib2 import request
    

    would do the job. Yet i get the following Error:

    Traceback (most recent call last):
      File "C:\Python27\NLTKHoofdstuk3.py", line 5, in <module>
        from urllib2 import request
    ImportError: cannot import name request
    

    I don't get it because i have urllib2 fully working on Python and the module request should be in the module urllib2 (i also don't get an Error when i type "import urllib2")

    So does anyone know why my module request is not working but my module urllib2 is

  • Niels Gorsel
    Niels Gorsel about 9 years
    I still get the same Error: Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> from urllib import Request ImportError: cannot import name Request
  • Ajay
    Ajay about 9 years
    @NielsGorsel it's R in Request and urllib2