Import urllib.request, ImportError: No module named request

家住魔仙堡 提交于 2019-11-28 21:12:47

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
Bu-gae Park

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)

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))

Use > Path\easy_install.exe requests if you have a windows machine, where easy_install can be found in your Python*\Scripts folder, if it was installed. (Note Path\easy_install.exe is an example, mine is C:\Python32\Scripts\easy_install.exe)

If you don't have easy install and are running on a windows machine, you can get it here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#distribute

If you manually want to add a library to a windows machine, you can download the compressed library, uncompress it, and then place it into the Lib folder of your python path.

OR

You need to install pip first and then install django-request using pip

pip install django-request

also install,

python setup.py install

then import

from urllib.request import urlopen

Helpful Tips:to chech this

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!