python telegram bot从dis发布一个图像文件

2024-10-03 23:22:36 发布

您现在位置:Python中文网/ 问答频道 /正文

{[来自磁盘的文件}

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?但我怎样才能得到呢?在


Tags: inidlibbotlinechatsiteupdate
2条回答

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

您的代码没有错误。

对于某些用户来说,此错误是临时错误。所以,你可能需要稍等。。在

上载文件时,请尝试增加超时时间。在

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

相关问题 更多 >