The write operation timed out в боте телеграм на Python
Вот решил сделать простой телеграм бот, который будет отправлять вам видео с инстаграм по указанной ссылке, чтобы вы могли скачать его. И тут появляется эта ошибка (конечно были и другие, но я их умудрился решить). Погуглил как исправить эту ошибку, но не нашел. И решил под конец обратится к вам.
Вот код
from bs4 import BeautifulSoup
import requests
import urllib.request
import telebot
from telebot.types import Message
import os.path
TOKEN = 'Here is my token'
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start', 'help'])
def echo_digits(message: Message):
bot.reply_to(message, 'NURULLO IS BAD GIRL')
return
@bot.edited_message_handler(content_types=['text'])
@bot.message_handler(content_types=['text'])
def insta_video(message: Message):
url = message.text
print(message.chat.id)
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Firefox/45.0'
}
page = requests.get(url, headers = headers)
soup = BeautifulSoup(page.text, 'html.parser')
video_meta = soup.find('meta', property='og:video')
firstpos=video_meta['content'].rfind("/")
lastpos=video_meta['content'].rfind(".")
video_name = video_meta['content'][firstpos+1:lastpos]
vv = video_name.split('?', 1)
video_name = vv[0]
video_link = video_meta['content']
print(video_meta['content'])
print(video_name)
video = open(video_name, 'rb')
bot.send_video(message.chat.id, video)
if os.path.isfile(video_name)==False:
urllib.request.urlretrieve(video_link, video_name)
video = open(video_name, 'rb')
bot.send_video(message.chat.id, video, timeout=60)
else:
video = open(video_name, 'rb')
bot.send_video(message.chat.id, video, timeout=60)
bot.polling(True)
Сама ошибка:
1199498323
https://scontent-iev1-1.cdninstagram.com/v/t50.2886-16/133843027_421920479161416_1900244851627179673_n.mp4?_nc_ht=scontent-iev1-1.cdninstagram.com&_nc_cat=100&_nc_ohc=TK6PwyuIF-UAX_-eBU9&oe=603AF877&oh=1b2d8f6ea58c7fa43d8317628265dcce
133843027_421920479161416_1900244851627179673_n.mp4
Traceback (most recent call last):
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen
chunked=chunked,
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1055, in _send_output
self.send(chunk)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 977, in send
self.sock.sendall(data)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1015, in sendall
v = self.send(byte_view[count:])
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 984, in send
return self._sslobj.write(data)
socket.timeout: The write operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 531, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen
chunked=chunked,
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1055, in _send_output
self.send(chunk)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 977, in send
self.sock.sendall(data)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1015, in sendall
v = self.send(byte_view[count:])
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 984, in send
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', timeout('The write operation timed out'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Khisrav\Documents\PyProjects\TelInstaBot\bot.py", line 58, in <module>
bot.polling(True)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 485, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 544, in __threaded_polling
raise e
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 507, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 117, in raise_exceptions
raise self.exception_info
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\Users\Khisrav\Documents\PyProjects\TelInstaBot\bot.py", line 47, in insta_video
bot.send_video(message.chat.id, video)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 913, in send_video
parse_mode, supports_streaming, disable_notification, timeout, thumb, width, height))
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 554, in send_video
return _make_request(token, method_url, params=payload, files=files, method='post')
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 128, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', timeout('The write operation timed out'))
[Finished in 16.8s with exit code 1]
[shell_cmd: python -u "C:\Users\Khisrav\Documents\PyProjects\TelInstaBot\bot.py"]
[dir: C:\Users\Khisrav\Documents\PyProjects\TelInstaBot]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\Khisrav\AppData\Local\Programs\Python\Python37-32\;C:\Users\Khisrav\AppData\Local\Microsoft\WindowsApps;]
Ошибка появляется после отправки боту ссылку на видео инстаграм