我无法发送位于 app 目录中的 *.txt 文件:
我在 /app 中有文件,我想用sendDocument方法发送它,
- Telepot lib案例:
file = open('report.txt', 'w')
file.write('report')
file.close()
telepot_bot.sendDocument(os.environ['ADMIN0'], document=file, caption='report.txt')
# or
telepot_bot.sendDocument(os.environ['ADMIN0'], document=file.name, caption='report.txt')
# or
telepot_bot.sendDocument(os.environ['ADMIN0'], document=os.path.realpath(file.name), caption='report.txt')
返回:
ValueError: I/O operation on closed file.
# or
telepot.exception.TelegramError: ('Bad Request: wrong file identifier/HTTP URL specified', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: wrong file identifier/HTTP URL specified'})
# or
telepot.exception.TelegramError: ('Bad Request: URL host is empty', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: URL host is empty'})
- python-telegram-bot库案例:
context.bot.send_document(os.environ['ADMIN0'], document=file, filename='report.txt')
# or
context.bot.send_document(os.environ['ADMIN0'], document=file.name, filename='report.txt')
# or
context.bot.send_document(os.environ['ADMIN0'], document=os.path.realpath(file.name), filename='report.txt')
返回:
ValueError: I/O operation on closed file.
# or
telegram.error.BadRequest: Wrong file identifier/http url specified
# or
telegram.error.BadRequest: Url host is empty
手册说:
“......使用 multipart/form-data 上传一个新的。最后你可以传递一个现有的 :class: telegram.Document 对象来发送。”
但我应该怎么做?