The libary sometimes cannot send files over 800MB with local bot server.[BUG]
Steps to Reproduce
- Download any file that is more 1gb from the internet,
- I tried to upload a video, a
.mkvfile, - try to upload to a group with
FilesBot.send_docuemnt(I have put a link to FilesBot program or class at the end, it is in additional context).
Expected behaviour
Libary should send the file to Local server, then local server should process the file and upload it to group while libaray should return the result
Actual behaviour
No error nor exception, everthing just stop.
Operating System
ubuntu 22LTS on github codespace
Version of Python, python-telegram-bot & dependencies
python-telegram-bot 21.1.1 (0.1.5-18-g067c55a) Bot API 7.2 Python 3.10.13 (main, Mar 5 2024, 18:35:01) [GCC 9.4.0]
Relevant log output
Log genearted by FilesBot.send_document 2024-07-10 09:31:56,459 - asyncio - DEBUG - Using selector: EpollSelector - /usr/local/python/3.10.13/lib/python3.10/asyncio/selector_events.py:54 function __init__ process:7013 module:selector_events 2024-07-10 09:31:56,461 - httpx - DEBUG - load_ssl_context verify=True cert=None trust_env=True http2=False - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpx/_config.py:80 function load_ssl_context process:7013 module:_config 2024-07-10 09:31:56,462 - httpx - DEBUG - load_verify_locations cafile='/home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/certifi/cacert.pem' - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpx/_config.py:146 function load_ssl_context_verify process:7013 module:_config 2024-07-10 09:31:56,483 - httpx - DEBUG - load_ssl_context verify=True cert=None trust_env=True http2=False - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpx/_config.py:80 function load_ssl_context process:7013 module:_config 2024-07-10 09:31:56,484 - httpx - DEBUG - load_verify_locations cafile='/home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/certifi/cacert.pem' - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpx/_config.py:146 function load_ssl_context_verify process:7013 module:_config 2024-07-10 09:31:56,489 - root - INFO - Getting bot delay for group - /workspaces/[redacted]/utils/database.py:362 function getBotDelay process:7013 module:database 2024-07-10 09:31:56,507 - root - INFO - Making request to http://[redacted]/?action=get-bot-delay&query=group&by=%40[redacted] with method GET - /workspaces/[redacted]/utils/utils.py:69 function make_request process:7013 module:utils 2024-07-10 09:31:56,517 - urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): [redacted] - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/urllib3/connectionpool.py:244 function _new_conn process:7013 module:connectionpool 2024-07-10 09:31:56,605 - urllib3.connectionpool - DEBUG - http://[redacted] "GET /?action=get-bot-delay&query=group&by=%40[redacted] HTTP/1.1" 200 26 - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/urllib3/connectionpool.py:549 function _make_request process:7013 module:connectionpool 2024-07-10 09:31:56,606 - root - INFO - Bot delay for group is 0.0 - /workspaces/[redacted]/utils/database.py:369 function getBotDelay process:7013 module:database 2024-07-10 09:31:56,607 - root - INFO - Uploading file video.mvk[1.6gb file] to group - /workspaces/[redacted]/bot/filesbot.py:195 function send_document process:7013 module:filesbot 2024-07-10 09:32:06,078 - telegram.Bot - DEBUG - Calling Bot API endpoint `sendDocument` with parameters `{'chat_id': '@[redacted]', 'document': <telegram._files.inputfile.InputFile object at 0x7cb7f50d3bc0>, 'disable_content_type_detection': True, 'disable_notification': True, 'caption': 'video at lagos store 1.1.3'}` - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/telegram/_bot.py:643 function _do_post process:7013 module:_bot 2024-07-10 09:32:06,100 - httpcore.connection - DEBUG - connect_tcp.started host='[redacted]' port=8080 local_address=None timeout=1800 socket_options=None - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpcore/_trace.py:85 function atrace process:7013 module:_trace 2024-07-10 09:32:06,118 - httpcore.connection - DEBUG - connect_tcp.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x7cb7f5089210> - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpcore/_trace.py:85 function atrace process:7013 module:_trace 2024-07-10 09:32:06,119 - httpcore.http11 - DEBUG - send_request_headers.started request=<Request [b'POST']> - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpcore/_trace.py:85 function atrace process:7013 module:_trace 2024-07-10 09:32:06,120 - httpcore.http11 - DEBUG - send_request_headers.complete - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpcore/_trace.py:85 function atrace process:7013 module:_trace 2024-07-10 09:32:06,120 - httpcore.http11 - DEBUG - send_request_body.started request=<Request [b'POST']> - /home/codespace/.cache/pypoetry/virtualenvs/[redacted]/lib/python3.10/site-packages/httpcore/_trace.py:85 function atrace process:7013 module:_trace
Additional Context
the filesbot program is this.send_document is the one uploading the video
I was able to upload the file after some time, i also used a third party libaray request toolbelt
async def sendDocumentRaw( self, path: str, filename: str, caption="", retries: int = 0 ) -> int: """ Sends a document to a group chat. Args: path (str): The path to the document file `Warning: this will remove the file after sending it.`. filename (str): The name of the document file. caption (str, optional): The caption for the document. Defaults to "". retries (int, optional): The number of retries in case of failure. Defaults to 0. Returns: int: The message ID of the sent document, or 0 if an error occurred. """ logger = self.logger logger.info(f"Uploading file {filename} to group") returnData: int = 0 await asyncio.sleep(self.database.getBotDelay("group", self._group_name)) try: if os.path.exists(path): url = f"{self._server}{self._token}/sendDocument" encoder = MultipartEncoder( fields={ "chat_id": self._group_name, "caption": caption, "disable_notification": "true", "document": (filename, open(path, "rb"), "text/plain"), } ) response = requests.post( url, data=encoder, headers={"Content-Type": encoder.content_type} ) if response.status_code == 200: returnData = response.json()["result"]["message_id"] logger.info(f"file {filename} uploaded to group") else: respondJson = response.json() if "description" in respondJson: if "bad request" in respondJson["description"].lower(): if retries < self.maxRetries: retries += 1 logger.warning( f"A retry after error occurred while trying to upload file , retrying in {self.retryIn} seconds" ) await asyncio.sleep(self.retryIn) returnData = await self.sendDocumentRaw( path, filename, caption, retries ) else: logger.error( f"An error occurred while trying to upload file max retries reached, could not get message id respond is : {response.text}" ) returnData = 0 else: logger.error( f"An error occurred while trying to upload file, could not get message id respond is : {response.text}" ) returnData = 0 else: logger.error( f"An error occurred while trying to upload file, could not get message id respond is : {response.text}" ) returnData = 0 else: returnData = 0 logger.error( f"An error occurred while trying to upload file, file {path} does not exist" ) except Exception as e: if retries < self.maxRetries: retries += 1 logger.warning( f"A retry after error occurred while trying to upload file , retrying in {self.retryIn} seconds" ) await asyncio.sleep(self.retryIn) returnData = await self.sendDocumentRaw( path, filename, caption, retries ) else: logger.exception(f"An error occurred while trying to upload file {e}") returnData = 0 finally: try: os.remove(path) logger.info(f"file {path} deleted") except Exception as e: logger.warning(f"unable to delete file {path}") return returnData