【问题标题】:kaggle kernels: urllib.request.urlopen not working for any urlkaggle 内核:urllib.request.urlopen 不适用于任何 url
【发布时间】: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

【问题讨论】:

    标签: python urllib2 kaggle


    【解决方案1】:

    这对你不起作用的原因是因为 Kaggle 内核目前没有互联网访问权限。因此,您无法进行需要内核内部网络连接的 API 调用。

    2018 年 8 月编辑:仅供参考,我们现在添加了对内核的 Internet 访问。 :) 您可以在编辑器的左侧栏中启用它。

    【讨论】:

    • 现在位于右侧栏中。在“设置”下有一个激活互联网访问的开关
    【解决方案2】:

    警告:您需要为您的内核启用 Internet 访问才能在其设置菜单中使用它。为了能够做到这一点,你必须通过手机在 Kaggle 注册一次。

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 2019-06-05
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 2011-12-26
      • 1970-01-01
      • 2019-12-27
      相关资源
      最近更新 更多