【问题标题】:Error sending image from file with python-telegram-bot使用 python-telegram-bot 从文件发送图像时出错
【发布时间】:2017-10-05 09:15:11
【问题描述】:

我从python telegram bot 的文件发送照片时遇到问题。 它适用于图片 URL,但在尝试从磁盘发送文件时效果不佳。

重现步骤

bot.send_photo(chat_id=update.message.chat_id, photo=open('/mydir/log.jpg', 'rb'))

出现错误:

*** BadRequest: Url host is empty

配置

  • 操作系统:Osx

  • Python:2.7 蟒蛇

  • -m 电报

    • _python-telegram-bot 8.0
    • 证书 2017.07.27.1
    • 未来 0.16.0
    • Python 2.7.13(默认,2016 年 12 月 18 日,07:03:39)[GCC 4.2.1 兼容 Apple LLVM 8.0.0 (clang-800.0.42.1)]_

根据文档,我们可以从磁盘传递文件https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#post-an-image-file-from-disk

【问题讨论】:

    标签: python-2.7 telegram python-telegram-bot


    【解决方案1】:

    问题出在 unicode 中的照片路径。

    photo = open(('/mydir/log.jpg').encode('utf-8'), 'rb')
    bot.send_photo(chat_id=update.message.chat_id, photo=photo)
    

    telegram.inputfile的_方法中,如果不发送完整的unicode形式,join会产生UnicodeDecodeError。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 2019-11-18
      • 2021-11-12
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      相关资源
      最近更新 更多