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

AttributeError: cannot access submodule 'request' of module 'urllib' (most likely due to a circular import)

import urllib.request

response = urllib.request.urlopen('http://127.0.0.1:9999/')
print(response)
for k, v in response.getheaders():
    print('{}: {}'.format(k, v))

我编辑了一个http.py文件,内容如上。然后在终端输入:python3 http.py

去执行它,它就会报错,如下:

Traceback (most recent call last):

  File "/Users/fangxiaoyan/Documents/pyPractise/http.py", line 3, in <module>

    import urllib.request

  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 88, in <module>

    import http.client

  File "/Users/fangxiaoyan/Documents/pyPractise/http.py", line 6, in <module>

    response = urllib.request.urlopen('http://127.0.0.1:9999')

               ^^^^^^^^^^^^^^

AttributeError: cannot access submodule 'request' of module 'urllib' (most likely due to a circular import)


但是如果我直接在终端输入python3,然后输入上面的代码去执行,又没有问题。这是为啥呢?


正在回答

1 回答

pycharm环境配置问题

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

AttributeError: cannot access submodule 'request' of module 'urllib' (most likely due to a circular import)

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信