[英]Pastebin pbwrap has AttributeError: __enter__ with io.open() on python 3.9.5
The pastebin package pbwrap from pypi always worked properly for me before but it doesn't work with python 3.9.5.来自 pypi 的 pastebin package pbwrap 以前对我来说总是正常工作,但它不适用于 python 3.9.5。 It's not able to read the input file and gives the error below.它无法读取输入文件并给出以下错误。
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_private=1, api_paste_name='test')
print(paste_url)
### pbwrap.py", line 180, in create_paste_from_file
### with io.open(
### AttributeError: __enter__
This turned out to be a bug that was introduced in 2020 when the module was upgraded to use utf-8.这原来是 2020 年模块升级为使用 utf-8 时引入的错误。 I have forked the pbwrap source code and submitted a fix.我已经分叉了 pbwrap 源代码并提交了一个修复程序。 The file read needed to be moved outside the context of the with io.open.需要将读取的文件移到 io.open 的上下文之外。
you can try by re-installing the package by pip command it will work for you您可以尝试通过 pip 命令重新安装 package 它将为您工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.