微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pastebin pbwrap 有 AttributeError: __enter__ with io.open() on python 3.9.5

如何解决Pastebin pbwrap 有 AttributeError: __enter__ with io.open() on python 3.9.5

pypi 的 pastebin 包 pbwrap 以前对我来说总是正常工作,但它不适用于 python 3.9.5。它无法读取输入文件并给出以下错误

from pbwrap import Pastebin   # https://pypi.org/project/pbwrap/

api_dev_key = r'your key'
username = r'your login'
password = r'your password'
pb = Pastebin(api_dev_key)
user_id = pb.authenticate(username,password)

### Pasting text to pastebin works as expected.
paste_url = pb.create_paste('this is a test',api_paste_private=1,api_paste_name='test')
print(paste_url)

### Make a simple text file to upload to pastebin
with open('test.txt','w') as f:
    f.write('This is line #1\n')
    f.write('This is line #2\n')

### When uploading a file to pastebin,an I/O error is returned from io.open() called from pbwrap
paste_url = pb.create_paste_from_file('test.txt',api_paste_name='test')
print(paste_url)

### pbwrap.py",line 180,in create_paste_from_file
###     with io.open(
### AttributeError: __enter__

解决方法

事实证明这是一个错误,是在 2020 年模块升级为使用 utf-8 时引入的。我已经分叉了 pbwrap 源代码并提交了一个修复程序。读取的文件需要移到 with io.open 的上下文之外。

,

你可以通过pip命令重新安装包试试 它会为你工作

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。