[英]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.