import urllib.requestfhand = urllib.request.urlopen("http://www.python.org")for line in fhand: print(line.decode().strip())這段代碼不起作用,我在 windows10 上使用 python3。每次我使用原子編輯器在命令提示符下運(yùn)行此代碼時(shí),都會(huì)收到以下錯(cuò)誤消息: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)**幫助我處理這段代碼,我也無(wú)法運(yùn)行urllib.request相關(guān)程序
1 回答

慕的地8271018
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
您的代碼對(duì)我來(lái)說(shuō)效果很好。嘗試刪除 'C:\Users\isha\Downloads\py4e\socket.py' 這個(gè)文件并再次運(yùn)行你的代碼。
添加回答
舉報(bào)
0/150
提交
取消