处理url中的列表的最佳方法是什么kaggle kernels
?
我尝试使用进行首次测试google.com
。
First Method
:使用urllib.request
import urllib.request resp = urllib.request.urlopen('http://www.google.com')
这会导致gai错误和urlopen错误[Errno -2]名称或服务未知
Second Method
:使用请求
import requests resp = requests.get('http://www.google.com')
这导致错误gaierror:[Errno -3]名称解析暂时失败,并且无法建立新连接:[Errno -3]名称解析暂时失败。
import urllib.request
req = urllib.request.Request('http://www.google.com')
print (req)
try:
response = urllib.request.urlopen(req)
print (response)
except urllib.error.URLError as e:
print (e.reason)
print("something wrong")
输出:
<urllib.request.Request object at 0x7fed1d00c518>
[Errno -2] Name or service not known
something wrong
我尝试按照stackoverflow answer的建议解析DNS解析。
解决该错误的方法是什么?为什么urlopen或请求在kaggle内核中不起作用?
我已经看到许多具有相同错误的内核:内核1 内核2 内核3。
这对您不起作用的原因是因为Kaggle Kernels当前无法访问互联网。结果,您无法进行需要内核中的网络连接的API调用。
编辑2018年8月:仅供参考,我们现在已向内核添加了互联网访问权限。:)您可以在编辑器的左侧栏中启用它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句