Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import urllib.request, ImportError: No module named request

I am trying to import urllib.request for python 2.7.10 on PyCharm 4.5.4 on Window 10 but getting the error "ImportError: No module named request".

like image 845
Raj Avatar asked Apr 21 '16 21:04

Raj


4 Answers

I have also faced the same error and Googled to solve it. urlib.request is for Python 3.0.

You may use the code below:

import urllib
urllib.urlopen(url)
like image 36
Bu-gae Park Avatar answered Nov 04 '22 04:11

Bu-gae Park


The urllib.request modules have been deprecated .. just use

import urllib

And for your function if you were earlier writing say

urllib.request.urlretrieve

Now you just write

urllib.urlretrieve
like image 178
KrackingCode Avatar answered Nov 04 '22 04:11

KrackingCode


You'll get this error if you try running a python 3 file with python 2.

like image 12
theninjagreg Avatar answered Nov 04 '22 03:11

theninjagreg


Try to use this in Python3

try:
    x = urllib.request.urlopen('https://www.google.com/search?q=test')
    print(x.read())

except Exception as e:
    print(str(e))
like image 2
Akash Kandpal Avatar answered Nov 04 '22 03:11

Akash Kandpal