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))
我編輯了一個(gè)http.py文件,內(nèi)容如上。然后在終端輸入:python3 http.py
去執(zhí)行它,它就會(huì)報(bào)錯(cuò),如下:
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,然后輸入上面的代碼去執(zhí)行,又沒有問題。這是為啥呢?
2024-07-15
pycharm環(huán)境配置問題