首页 文章

Google colab文件下载无法获取错误

提问于
浏览
0

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

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()

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

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

Click here to see the screenshot of my code and the error

请帮帮我

1 回答

  • 0

    你需要启用 third-party cookies 但是要知道它只适用于Chrome浏览器,请打开

    chrome://settings/content/cookies
    

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

    colab.research.google.com
    

相关问题