为了账号安全,请及时绑定邮箱和手机立即绑定

Python urllib 属性错误

Python urllib 属性错误

莫回无 2023-04-18 14:48:54
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' 这个文件并再次运行你的代码。



查看完整回答
反对 回复 2023-04-18
  • 1 回答
  • 0 关注
  • 121 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信