kaggle kernels: urllib.request.urlopen not working for any url

℡╲_俬逩灬. 提交于 2020-02-04 02:58:26

问题


What is the best way to handle fetching of list of urls in kaggle kernels?

I tried first testing with google.com.

First Method: Using urllib.request

import urllib.request resp =  urllib.request.urlopen('http://www.google.com')

This lead to error of gai and urlopen error [Errno -2] Name or service not known

Second Method: Using requests

import requests resp = requests.get('http://www.google.com')

This lead to error gaierror: [Errno -3] Temporary failure in name resolution and Failed to establish 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")

Output:

<urllib.request.Request object at 0x7fed1d00c518>
[Errno -2] Name or service not known
something wrong

I tried resolving DNS resolve as suggested by stackoverflow answer.

What is the way around to fix this error? Why is urlopen or requests not working in kaggle kernels?
I have seen many kernels with the same errors kernel 1 kernel 2 kernel 3.


回答1:


The reason this isn't working for you is because Kaggle Kernels currently don't currently have internet access. As a result, there's not a way for you to make API calls that require a network connection from within kernels.

Edit August 2018: Just FYI, we have now added internet access to Kernels. :) You can enable it in the left-hand side bar from within the editor.




回答2:


Caveat: You need to enable Internet Access for your Kernel be able to use it in its Setting Menu. And to be able to do that, you must register once via mobile with Kaggle.



来源:https://stackoverflow.com/questions/48969283/kaggle-kernels-urllib-request-urlopen-not-working-for-any-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!