2017-05-03 86 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))