慕粉2044547211
2024-03-05 20:41
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,然后输入上面的代码去执行,又没有问题。这是为啥呢?
pycharm环境配置问题
Python3 进阶教程(新版)
41910 学习 · 236 问题
相似问题
回答 1