commit 01f92d4ff5f4a33f333588419870be7928d70fdc
parent e9a1369504d09d9ad14c205d55c3199801923605
Author: archiveanon <>
Date: Fri, 24 Apr 2026 16:39:57 +0000
Raise status on failure and backoff on uploads
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/gofile/api.py b/src/gofile/api.py
@@ -4,6 +4,7 @@ import asyncio
import collections
import enum
import io
+import itertools
import pathlib
from typing import Any, AsyncIterator, Generic, Iterator, Optional, TypeVar
@@ -82,6 +83,7 @@ async def _gofile_api_get(*args, type: type[T], **kwargs) -> T:
# if the status is not 'ok', an exception is raised
async with httpx.AsyncClient() as client:
r = await client.get(*args, **kwargs)
+ r.raise_for_status()
# suppress the valid-type error since mypy doesn't cannot use runtime-specialized types
# but msgspec needs to do so
@@ -98,6 +100,7 @@ async def _gofile_api_post(*args, type: type[T], **kwargs) -> T:
# if the status is not 'ok', an exception is raised
async with httpx.AsyncClient() as client:
r = await client.post(*args, **kwargs)
+ r.raise_for_status()
# see typing woes at _gofile_api_get
result = msgspec.json.decode(r.text, type=GofileServerResponse[type]) # type: ignore[valid-type]
@@ -128,7 +131,7 @@ async def upload_single(
# we return a GofileUpload instead of a GofileUploadResult so there's consistency between upload_single / upload_multiple
# automatically shorten long file names in small terminals (e.g. split panes)
- while True:
+ for attempt in itertools.count(1):
try:
filepath = pathlib.Path(str(file.name))
post_data: dict[str, Any] = {
@@ -146,6 +149,7 @@ async def upload_single(
break
except httpx.HTTPError as e:
print(e)
+ await asyncio.sleep(min(300, 10 * (1.2**attempt)))
pass
return GofileUpload(file, upload_result)