0

this work :

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

But if I did before :

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

I can't do :

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

The error is :

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

I use python 3.5.2 win or linux

Thanks for answer

jgirardet
  • 109
  • 2
  • 9

2 Answers2

1

sorry I didn't see your answer.

My trouble was I wanted to send a downloaded document, not a document on disk.

I resolved it like this :

mybot.sendDocument(chat_id=chatid,document=io.BytesIO(self.downloaded_file))
jgirardet
  • 109
  • 2
  • 9
0

Try to send just a file object:

mybot.sendDocument(chat_id=chatid, document=open('bla.pdf', 'rb'))
Vladimir Vlasov
  • 1,860
  • 3
  • 25
  • 38