-2

Result after google [see Post an image file from disk]

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

Why doesn't this work?

Maybe I should use the other way to do get file_id instead? But how do I get it?

kajetons
  • 4,481
  • 4
  • 26
  • 37
  • Do not post images of code/error. Please edit your question and paste both the code and the error traceback as plain text. – baduker Apr 06 '18 at 19:43

2 Answers2

1

Try to increase the timeout when uploading files.

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

jeffffc
  • 772
  • 4
  • 13
0

Are you using a proxy server? It may be the reason behind this problem. Are you trying these codes on your local machine or remote server? If it's remote server, then please try on local machine.

There is nothing wrong in your code.

This error is a temporary error for some users. So, you might want to wait a little..