I’m encountering the error telethon.errors.rpcbaseerrors.FloodError: RPCError 420: FLOOD_PREMIUM_WAIT_3 (caused by SaveBigFilePartRequest) when attempting to upload a 2 GB video. Is there any way to resolve this issue, or do I need to wait for the next Telethon update?
Code:
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
async def upload_file_with_retry(client, file_path, part_size_kb=512):
"""Uploads a file in parts with FloodWaitError handling."""
part_size = part_size_kb * 1024
file_size = os.path.getsize(file_path)
parts_count = (file_size + part_size - 1) // part_size
logging.info(f"Starting file upload: {file_path}, size: {file_size} bytes, parts: {parts_count}")
with open(file_path, 'rb') as f:
uploaded_file = None
for part_num in range(parts_count):
logging.info(f"Uploading part {part_num + 1} of {parts_count}")
part_start = part_num * part_size
f.seek(part_start)
part_data = f.read(part_size)
wait_time = 5
while True:
try:
uploaded_file = await client.upload_file(
bytes(part_data),
file_name=os.path.basename(file_path),
file_size=file_size
)
logging.info(f"Part {part_num + 1} successfully uploaded")
break
except FloodWaitError as e:
logging.warning(
f"Flood error during upload! File: {file_path}, part {part_num + 1}, waiting {wait_time} seconds, error: {e}")
await asyncio.sleep(wait_time)
wait_time *= 2
return uploaded_file
async def main():
async with TelegramClient("session_name", api_id, api_hash) as client:
caption = "caption"
media_group = [
types.InputMediaUploadedDocument(
file=await upload_file_with_retry(client, "video.mp4"),
thumb=await upload_file_with_retry(client, "image.jpg"),
mime_type='video/mp4',
attributes=[
types.DocumentAttributeVideo(
duration=2940,
w=1920,
h=1080,
supports_streaming=True
)
]
)
]
for i in range(2, 11):
video_file = f"video{i}.mp4"
image_file = f"image{i}.jpg"
if os.path.exists(video_file) and os.path.exists(image_file):
media_group.append(
types.InputMediaUploadedDocument(
file=await upload_file_with_retry(client, video_file),
thumb=await upload_file_with_retry(client, image_file),
mime_type='video/mp4',
attributes=[
types.DocumentAttributeVideo(
duration=2940,
w=1920,
h=1080,
supports_streaming=True
)
]
)
)
else:
print(f"File not found: {video_file}")
try:
await client.send_file(
" ",
media_group,
caption=caption
)
except FloodWaitError as e:
print(f"Flood error during sending! Waiting for {e.seconds} seconds...")
await asyncio.sleep(e.seconds)
asyncio.run(main())
I tried changing the chunk size, but it didn’t help. I’m new to programming.
New contributor
1 1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.