urllib.request not working

+1 Rishabh gupta · December 29, 2014
i am trying to download a image from the web  using urllib.request,but i am getting import error which says "no module named request"

i am using pycharm 4.0.3 which actually doesn't have urllib.request module .so i installed a package named "yieldfrom.urllib.request" but still i am getting invalid syntax error .

my code:
import yieldfrom.urllib.request



can anyone explain what am i doing wrong ..??

Post a Reply


Oldest  Newest  Rating
0 Vaggelis Theodoridis · December 30, 2014
Maybe you have installed python 2?
If so, in python 2 its urllib2, so you should use urllib2.urlopen(url)
In python 3 became urllib where we import urllib.request and then we use urllib.request.urlopen(url)
0 Rishabh gupta · December 30, 2014
 i was using the python 2.7.9 interpreter so i changed it to 3.4 but i still i am getting the error...
my code:
import urllib.request



and this is what i get ..

0 Vaggelis Theodoridis · December 30, 2014
Im sorry but it should work. Something is meshed up.
Does it look inside python when importing? Print ur sys path so we can see from where does it look for modules:
import sys

Also, how u named the file? maybe a strange name like urllib.py? It will mesh things up with python..
0 Vaggelis Theodoridis · December 30, 2014
Oh, now that im thinking it again, maybe it cant find the module urllib because in path there is only python2. Check it ;)
0 Rishabh gupta · December 30, 2014

i actually named my file urllib.py...and basically this was the only reason of why i kept getting errors ..

changing  the name of file to url.py sorted the issue ..in future if anyone encounters this issue ,just make sure you keep your files
name different from modules or packages name... 

and thanks vaggelis
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator