0

I'm trying to reshape my data, then create it like an image, using PIL. After that I would like to send it without hands a picture into a chat.

srcData = np.reshape(srcData, [row, col, height]) # reshape srcData
img = Image.fromarray(srcData)
url = 'https://api.telegram.org/file/bot<TOKEN>/sendPhoto/'
response = requests.get(url, stream=True)
with open('img.png', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response # HERE. I'm creating a picture into int a png file

f=open(out_file.name,'rb') #Trying to open
bot.send_photo(chat_id=chat_id, photo=f)# then send

I don't understand, why I have an error:

ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request.

Can you help me,please? I have no idea , what I should do. Please.

mencucci
  • 180
  • 1
  • 10
X22
  • 11
  • 5
  • It seems that you are just using an example. You need that in you use an actual token. It looks like: "Each bot is given a unique authentication token when it is created. The token looks something like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11, but we'll use simply in this document instead. You can learn about obtaining tokens and generating new ones in this document. " – fernand0 Nov 07 '17 at 16:50
  • 1
    @fernand0 No, I'm using my token, it's just long, I decided to write just ``.Sorry. – X22 Nov 07 '17 at 16:53
  • And 'chat_id' is also correctly defined? Moreover, if you are using Telepot, do you need url and the request? – fernand0 Nov 07 '17 at 17:03
  • @fernand0 Yes, everything is okay with that, I really don't know what's the problem , I'm stuck. I was even try to send the same picture , which I upload , it's okay. But when I create new one , and try to send it , I have an error. – X21 Nov 07 '17 at 17:06
  • Sorry, it is quite difficult to be able to help without the actual code. And the line where the error appears. – fernand0 Nov 07 '17 at 17:09
  • @fernand0 Can I send it to you? Please, can you help? – X21 Nov 07 '17 at 17:10
  • I'd suggest following the examples in: http://telepot.readthedocs.io/en/latest/ First, send a text message, if everything is ok, try with images, and so on... – fernand0 Nov 07 '17 at 17:15
  • @fernand0 Okay, thank tou, i will try – X22 Nov 07 '17 at 17:35

0 Answers0