【问题标题】:python telegram bot Post an image file from diskpython telegram bot 从磁盘发布图像文件
【发布时间】:2018-04-06 19:41:54
【问题描述】:

Result after google [请参阅从磁盘发布图像文件]

In[2]: from telegram import Bot

In[3]: bot = Bot(token)

In[4]: update = bot.get_updates()[0]

In[5]: update
Out[5]: <telegram.update.Update at 0x1a295c18>

In[6]: chat_id = update["message"]["chat"]["id"]

In[7]: bot.send_photo(chat_id=chat_id, photo=open("test.jpg", "rb"))
Traceback (most recent call last):

  File "<ipython-input-9-4c19142e0fd3>", line 1, in <module>
    bot.send_photo(chat_id=chat_id, photo=open("test.jpg", "rb"))

  File "C:\Users\Cheung\Anaconda3\lib\site-packages\telegram\bot.py", line 60, in decorator
    result = func(self, *args, **kwargs)

  File "C:\Users\Cheung\Anaconda3\lib\site-packages\telegram\bot.py", line 85, in decorator
    result = self._request.post(url, data, timeout=kwargs.get('timeout'))

  File "C:\Users\Cheung\Anaconda3\lib\site-packages\telegram\utils\request.py", line 265, in post
    'POST', url, body=data.to_form(), headers=data.headers, **urlopen_kwargs)

  File "C:\Users\Cheung\Anaconda3\lib\site-packages\telegram\utils\request.py", line 196, in _request_wrapper
    raise NetworkError('urllib3 HTTPError {0}'.format(error))

NetworkError: urllib3 HTTPError ('Connection aborted.', timeout('The write operation timed out',))

Actual Coding and error

为什么这不起作用?

也许我应该使用其他方式来获取file_id?但是我怎么得到它呢?

【问题讨论】:

  • 不要发布代码/错误的图像。请编辑您的问题并将代码和错误回溯粘贴为纯文本。

标签: python bots telegram python-telegram-bot


【解决方案1】:

您是否使用代理服务器?这可能是这个问题背后的原因。您是在本地机器还是远程服务器上尝试这些代码?如果是远程服务器,请在本地机器上尝试。

您的代码没有任何问题。

此错误是某些用户的临时错误。所以,你可能想等一下..

【讨论】:

    【解决方案2】:

    上传文件时尽量增加超时时间。

    bot.send_photo(chat_id=chat_id, photo=open("test.jpg", "rb"), timeout=100)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-07
      • 2016-01-10
      • 2015-11-26
      • 1970-01-01
      • 2019-11-18
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多