2017-05-03 51 views
0

这项工作:在python-电报机器人发送二进制与sendDocument

mybot.sendDocument(chat_id=chatid, document=open('bla.pdf', rb')) 

但是,如果我做之前:

with open('bla.pdf', 'rb') as fp: 
    b = fp.read() 

我不能这样做:

mybot.sendDocument(chat_id=chatid, document=b) 

的错误是:

TypeError: Object of type 'bytes' is not JSON serializable

我使用Python 3.5.2赢或Linux

谢谢回答

回答

0

尝试发送只是一个文件对象:

mybot.sendDocument(chat_id=chatid, document=open('bla.pdf', 'rb')) 
0

对不起,我没有看到你的答案。

我的麻烦是我想发送一个下载的文件,而不是磁盘上的文件。

我解决这样的:

mybot.sendDocument(chat_id=chatid,document=io.BytesIO(self.downloaded_file))