【问题标题】:Can i send savfig to python telegram bot我可以将 savfig 发送到 python 电报机器人吗
【发布时间】:2019-11-09 12:05:57
【问题描述】:

我尝试添加 bot.sendPhoto(chat_id=chat_id, photo='http://s33.postimg.org/plci93h4v/image.png'),我有 savfig 并且需要将图像发送到我的电报机器人

import telebot
from flask import Flask, request


token = '9542...................ke8nT10'

URL = 'http://re......here.com/'
bot = telebot.TeleBot(token, threaded=False)
bot.remove_webhook()
bot.set_webhook(url=URL)

app = Flask(__name__)
@app.route('/', methods=['POST'])
def webhook():
    update = telebot.types.Update.de_json(request.stream.read().decode('utf-8'))
    bot.process_new_updates([update])
    return 'ok',200

def code:
        plt.savefig('plot_name.png', dpi = 300)

@bot.message_handler(commands=['start'])  # welcome message handler
def start(message):
    bot.sendPhoto(chat_id=chat_id)

我正在尝试将 savfig 以 code: function 发送到我的电报机器人

【问题讨论】:

  • 您是否尝试过首先下载照片?例如在 urllib 的帮助下,然后通过 sendPhoto(chat_id = chat_id, photo = open('file.png', 'rb')) 发送它?
  • pythonanywhrre server 中有代码,怎么下载

标签: python-3.x matplotlib telegram telegram-bot python-telegram-bot


【解决方案1】:

bot.send_photo(chat_id, photo=open('plot_name.png', 'rb'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-03-19
    • 2017-06-16
    • 1970-01-01
    • 2021-07-09
    相关资源
    最近更新 更多