From 6dcfcf6b81ccb16a67e642ab1cead92650fe39cc Mon Sep 17 00:00:00 2001 From: tangyoha Date: Wed, 27 Dec 2023 17:12:05 +0800 Subject: [PATCH 1/3] fix: use get_session to get session when download --- hydrogram/client.py | 26 ++------------------------ hydrogram/methods/__init__.py | 2 +- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/hydrogram/client.py b/hydrogram/client.py index 080ff756b..8ee6ba9f6 100644 --- a/hydrogram/client.py +++ b/hydrogram/client.py @@ -48,7 +48,7 @@ VolumeLocNotFound, ) from hydrogram.handlers.handler import Handler -from hydrogram.methods import Methods +from hydrogram.methods import Methods, get_session from hydrogram.session import Auth, Session from hydrogram.storage import BaseStorage, SQLiteStorage from hydrogram.types import TermsOfService, User @@ -929,30 +929,8 @@ async def get_file( dc_id = file_id.dc_id - session = Session( - self, - dc_id, - await Auth(self, dc_id, await self.storage.test_mode()).create() - if dc_id != await self.storage.dc_id() - else await self.storage.auth_key(), - await self.storage.test_mode(), - is_media=True, - ) - try: - await session.start() - - if dc_id != await self.storage.dc_id(): - exported_auth = await self.invoke( - raw.functions.auth.ExportAuthorization(dc_id=dc_id) - ) - - await session.invoke( - raw.functions.auth.ImportAuthorization( - id=exported_auth.id, bytes=exported_auth.bytes - ) - ) - + session = await get_session(self, dc_id) r = await session.invoke( raw.functions.upload.GetFile( location=location, offset=offset_bytes, limit=chunk_size diff --git a/hydrogram/methods/__init__.py b/hydrogram/methods/__init__.py index d8c38f795..50574a262 100644 --- a/hydrogram/methods/__init__.py +++ b/hydrogram/methods/__init__.py @@ -28,7 +28,7 @@ from .password import Password from .users import Users from .utilities import Utilities - +from .messages.inline_session import get_session class Methods( Advanced, From e8926ffcbb061e89d988ad029b7418932e9b9a94 Mon Sep 17 00:00:00 2001 From: tangyoha Date: Wed, 27 Dec 2023 17:31:52 +0800 Subject: [PATCH 2/3] fix: use get_session to get session when download --- hydrogram/methods/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydrogram/methods/__init__.py b/hydrogram/methods/__init__.py index 50574a262..d8c38f795 100644 --- a/hydrogram/methods/__init__.py +++ b/hydrogram/methods/__init__.py @@ -28,7 +28,7 @@ from .password import Password from .users import Users from .utilities import Utilities -from .messages.inline_session import get_session + class Methods( Advanced, From 8ee32822598860fe266ef035e72638095b114bf3 Mon Sep 17 00:00:00 2001 From: Hitalo Date: Mon, 29 Jan 2024 20:30:31 -0300 Subject: [PATCH 3/3] fix: import get_session in client --- hydrogram/client.py | 3 ++- news/15.fix.rst | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 news/15.fix.rst diff --git a/hydrogram/client.py b/hydrogram/client.py index 34527ce2f..a69c557b1 100644 --- a/hydrogram/client.py +++ b/hydrogram/client.py @@ -48,7 +48,8 @@ VolumeLocNotFound, ) from hydrogram.handlers.handler import Handler -from hydrogram.methods import Methods, get_session +from hydrogram.methods import Methods +from hydrogram.methods.messages.inline_session import get_session from hydrogram.session import Auth, Session from hydrogram.storage import BaseStorage, SQLiteStorage from hydrogram.types import ListenerTypes, TermsOfService, User diff --git a/news/15.fix.rst b/news/15.fix.rst new file mode 100644 index 000000000..5570b6e73 --- /dev/null +++ b/news/15.fix.rst @@ -0,0 +1 @@ +Use `get_session` to get session when downloadind files