Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from urllib2 import request - cannot import name request

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

like image 642
Niels Gorsel Avatar asked Apr 07 '15 11:04

Niels Gorsel


People also ask

How to fix ‘no module named ‘urllib2’ in Python 3?

urllib2 is used in python 2.x, so if you use urllib2 in python 3.x, you will get this error: No module named ‘urllib2’. To fix this error, we should use python 2.x or replace urllib.request to replace it.

What is urllib request in Python?

urllib.request is a Python module for fetching URLs (Uniform Resource Locators). It offers a very simple interface, in the form of the urlopen function. This is capable of fetching URLs using a variety of different protocols.

What kind of errors can urllib2 handle?

if the response is a “redirection” that requests the client fetch the document from a different URL, urllib2 will handle that for you). For those it can’t handle, urlopen will raise an HTTPError. Typical errors include ‘404’ (page not found), ‘403’ (request forbidden), and ‘401’ (authentication required).

Is there a French translation of the urllib request?

There is a French translation of an earlier revision of this HOWTO, available at urllib2 - Le Manuel manquant. urllib.request is a Python module for fetching URLs (Uniform Resource Locators).


1 Answers

Try using

from urllib2 import Request

instead of

from urllib2 import request

Check the official documentation

like image 57
Ajay Avatar answered Sep 22 '22 01:09

Ajay