【发布时间】:2018-08-04 18:35:51
【问题描述】:
处理在kaggle kernels 中获取网址列表的最佳方法是什么?
我尝试使用 google.com 进行第一次测试。
First Method: 使用 urllib.request
import urllib.request resp = urllib.request.urlopen('http://www.google.com')
这导致gai和urlopen错误[Errno -2] Name or service not known
Second Method:使用请求
import requests resp = requests.get('http://www.google.com')
这导致错误gaierror: [Errno -3] Temporary failure in name resolution and Failed to setup a new connection: [Errno -3] Temporary failure in name resolution。
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 或 requests 在 kaggle 内核中不起作用?
我见过很多内核都有同样的错误kernel 1kernel 2kernel 3。
【问题讨论】: