import urllib.requestfhand = urllib.request.urlopen("http://www.python.org")for line in fhand: print(line.decode().strip())这段代码不起作用,我在 windows10 上使用 python3。每次我使用原子编辑器在命令提示符下运行此代码时,都会收到以下错误消息:Traceback (most recent call last): File "C:\Users\isha\Downloads\py4e\trial.py", line 1, in <module> import urllib.request File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 88, in <module> import http.client File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 71, in <module> import email.parser File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\parser.py", line 12, in <module> from email.feedparser import FeedParser, BytesFeedParser File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\feedparser.py", line 27, in <module> from email._policybase import compat32 File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\_policybase.py", line 9, in <module> from email.utils import _has_surrogates File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\utils.py", line 29, in <module> import socket File "C:\Users\isha\Downloads\py4e\socket.py", line 5, in <module> mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)**AttributeError: partially initialized module 'socket' has no attribute 'AF_INET' (most likely due to a circular import)**帮助我处理这段代码,我也无法运行urllib.request相关程序
1 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
您的代码对我来说效果很好。尝试删除 'C:\Users\isha\Downloads\py4e\socket.py' 这个文件并再次运行你的代码。
添加回答
举报
0/150
提交
取消