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
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.
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.
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).
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).
Try using
from urllib2 import Request
instead of
from urllib2 import request
Check the official documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With