简体   繁体   English

如何将 Jupyter 部署到 Medium? “AttributeError: 'PosixPath' object 没有属性 'read'

[英]How do I deploy Jupyter to Medium? "AttributeError: 'PosixPath' object has no attribute 'read'

I'm trying to deploy Jupyter Notebook to Medium with jupyter_to_medium and still getting the same error.我正在尝试使用 jupyter_to_medium 将 Jupyter Notebook 部署到 Medium,但仍然出现相同的错误。 Have tried both Safari and Chrome. Safari 和 Chrome 都试过了。 I have integration tokens.我有集成令牌。

MacBook Pro mid 2017 MacBook Pro 2017 年中期

Failed to post to Medium
Returned error message below

"AttributeError: 'PosixPath' object has no attribute 'read'

Traceback (most recent call last):
File \"/usr/local/lib/python3.7/site-packages/jupyter_to_medium/_bundler.py\", line 37, in upload
data = publish(**kwargs)
File \"/usr/local/lib/python3.7/site-packages/jupyter_to_medium/_publish_to_medium.py\", line 299, in publish
chrome_path, save_markdown, table_conversion)
File \"/usr/local/lib/python3.7/site-packages/jupyter_to_medium/_publish_to_medium.py\", line 41, in __init__
self.nb = self.get_notebook()
File \"/usr/local/lib/python3.7/site-packages/jupyter_to_medium/_publish_to_medium.py\", line 76, in get_notebook
return nbformat.read(self.filename, as_version=4)
File \"/usr/local/lib/python3.7/site-packages/nbformat/__init__.py\", line 141, in read
return reads(fp.read(), as_version, **kwargs)
AttributeError: 'PosixPath' object has no attribute 'read'
"

I run into the same error in Python3.7.我在 Python3.7 中遇到了同样的错误。 Here is what worked for me:这是对我有用的:

The failure cause by this function call reads(fp.read(), as_version, **kwargs) in File \"/usr/local/lib/python3.7/site-packages/nbformat/__init__.py\".此 function 调用导致的失败reads(fp.read(), as_version, **kwargs) in File \"/usr/local/lib/python3.7/site-packages/nbformat/__init__.py\". Apparently, fp is a path string , you cannot use read() directly on it.显然, fp是一个路径string ,你不能直接在它上面使用read()

Changes:变化:

Add the following lines before it:在它之前添加以下行:

text = None
with open(fp, 'r') as f:
     text = f.read()

and update the original line并更新原始行

return reads(fp.read(), as_version, **kwargs)

to

return reads(text, as_version, **kwargs)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'PosixPath' 对象没有属性 'path' - AttributeError: 'PosixPath' object has no attribute 'path' AttributeError: 'PosixPath' object 在构建 heroku 应用程序时没有属性 'read_text' - AttributeError: 'PosixPath' object has no attribute 'read_text' while building heroku app Weasyprint 在调用 write_pdf 时获得未定义的属性:“AttributeError: 'PosixPath' 对象没有属性 'read_text'” - Weasyprint get undefined property at invoking write_pdf: "AttributeError: 'PosixPath' object has no attribute 'read_text'" 在服务器上运行 collectstatic :AttributeError: 'PosixPath' 对象没有属性 'startswith' - Running collectstatic on server : AttributeError: 'PosixPath' object has no attribute 'startswith' 在 Google Colab 中使用 pathlib:AttributeError: 'PosixPath' object 没有属性 'ls' - Using pathlib in Google Colab: AttributeError: ‘PosixPath’ object has no attribute ‘ls’ 我收到一条错误消息,指出 AttributeError: 'str' object has no attribute 'read',我不知道如何修复它 - I'm getting an error that says AttributeError: 'str' object has no attribute 'read' and i do not know how to fix it AttributeError: 'function' object 没有属性 'read' — 我该如何修复? - AttributeError: 'function' object has no attribute 'read' — HOW CAN I FIX? 如何修复此 AttributeError: 'SubRequest' object 没有属性 'getfuncargvalue'? - How do I fix this AttributeError: 'SubRequest' object has no attribute 'getfuncargvalue'? 我该如何解决这个 AttributeError: 'NoneType' object has no attribute 'text'? - How do i fix this AttributeError: 'NoneType' object has no attribute 'text'? 我该如何修复 AttributeError: 'Tk' object has no attribute 'open' - how do I fix AttributeError: 'Tk' object has no attribute 'open'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM