URLLib import error
I am not able to use urllib.request, I have tried the below code in pycharm and python IDE its working fine in python IDE however its not working in pycharm community edition
I am using python 3.5.2 and configured the same as project interpreter in pycharm
import urllib.request , urllib.parse , urllib.error
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
for line in fhand:
print(line.decode().rstrip())
Below is the error code i am getting
"C:\Program Files (x86)\Python35-32\python.exe" "C:/PycharmProjects/pythonforeveryone/Web Data/socket.py"
Traceback (most recent call last):
File "C:/PycharmProjects/pythonforeveryone/Web Data/socket.py", line 1, in <module>
import urllib.request , urllib.parse , urllib.error
File "C:\Program Files (x86)\Python35-32\lib\urllib\request.py", line 88, in <module>
import http.client
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Program Files (x86)\Python35-32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Program Files (x86)\Python35-32\lib\email\feedparser.py", line 27, in <module>
from email import message
File "C:\Program Files (x86)\Python35-32\lib\email\message.py", line 16, in <module>
from email import utils
File "C:\Program Files (x86)\Python35-32\lib\email\utils.py", line 29, in <module>
import socket
File "C:\PycharmProjects\pythonforeveryone\Web Data\socket.py", line 3, in <module>
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
AttributeError: module 'urllib' has no attribute 'request'
Process finished with exit code 1
Please sign in to leave a comment.
Hi Na Singhall! I believe there's a file/package named urllib somewhere in your project and because of PyCharm adds it's parent directory to the PYTHONPATH Python can't resolve name collision. Replace your code with:
and check the module path printed - it should lead to the cause.
Thanks for your help Pavel, its working now.
Thank you soo much Pavel Karateev. Its working for me too now XD.