[英]Python3 error : AttributeError: module 'urllib' has no attribute 'request'
I am trying to run a script in python3 (tried with 3.7.4 and 3.8.0) which uses urllib.request
and urllib.error
.我正在尝试在 python3 中运行一个脚本(尝试使用 3.7.4 和 3.8.0),它使用
urllib.request
和urllib.error
。
I tried importing in the following ways:我尝试通过以下方式导入:
import urllib
and和
from urllib import request
but in both the above cases I get error:但在上述两种情况下,我都会收到错误:
AttributeError: module 'urllib' has no attribute 'request'
I haven't installed anything related to urllib
as it comes with python3我没有安装任何与
urllib
相关的东西,因为它带有 python3
Please suggest how should this be imported, thanks!请建议如何导入,谢谢!
Worked with following import:使用以下导入:
import urllib.request
Since urllib is a folder and request is a file inside urllib, you should use:由于 urllib 是一个文件夹,而 request 是 urllib 中的一个文件,你应该使用:
import urllib.request as request
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.