Google Colab文件下载未能获取错误 [英] Google colab file download failed to fetch error

查看:70
本文介绍了Google Colab文件下载未能获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Google colab制作了一个字典,将其转储到json文件中,然后通过以下代码将该文件下载到我的笔记本电脑中:

I used google colab to make a dictionary, dump it into a json file and download the file into my laptop by this code:

from google.colab import files
import json

dict = {'apple': 'fruit', 'mango': 'fruit', 'carrot': 'vegetable', 'brocoli': 'vegetable', 'cat': 'animal'}

with open('sampleDictionary.json', 'w') as f:
  json.dump(dict, f)

files.download('sampleDictionary.json')
f.close()

当我尝试运行此代码时,它给出此错误:

When I try to run this code, it gives this error:

MessageError                              Traceback (most recent call last)
<ipython-input-29-1251d71a0a36> in <module>()
      7   json.dump(dict, f)
      8 
----> 9 files.download('sampleDictionary.json')
     10 f.close()

/usr/local/lib/python3.6/dist-packages/google/colab/files.py in download(filename)
    176       'port': port,
    177       'path': _os.path.abspath(filename),
--> 178       'name': _os.path.basename(filename),
    179   })

/usr/local/lib/python3.6/dist-packages/google/colab/output/_js.py in eval_js(script, ignore_result)
     37   if ignore_result:
     38     return
---> 39   return _message.read_reply_from_input(request_id)
     40 
     41 

/usr/local/lib/python3.6/dist-packages/google/colab/_message.py in read_reply_from_input(message_id, timeout_sec)
    104         reply.get('colab_msg_id') == message_id):
    105       if 'error' in reply:
--> 106         raise MessageError(reply['error'])
    107       return reply.get('data', None)
    108 

MessageError: TypeError: Failed to fetch

点击此处查看我的代码和错误的屏幕截图

请帮帮我

推荐答案

您需要启用third-party cookies,但目前仅适用于Chrome浏览器,请打开

you need to enable third-party cookies but for now it only works for Chrome browser, open

chrome://settings/content/cookies

确保已禁用Block third-party cookies的选项,然后单击Allow部分中的add按钮,然后添加

make sure the option for Block third-party cookies is disabled and click add button in Allow section then add

colab.research.google.com

这篇关于Google Colab文件下载未能获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆