From 29f2b310f18031f68a76d0235dd3806df7cc4b6d Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 14 Jun 2024 19:40:36 +0200 Subject: [PATCH 1/2] Fix: aiohttp issues a DeprecationWarning For passing bytes to a file upload instead of a BytesIO --- src/aleph/sdk/client/authenticated_http.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/aleph/sdk/client/authenticated_http.py b/src/aleph/sdk/client/authenticated_http.py index 755a4557..df4e4a35 100644 --- a/src/aleph/sdk/client/authenticated_http.py +++ b/src/aleph/sdk/client/authenticated_http.py @@ -3,6 +3,7 @@ import logging import ssl import time +from io import BytesIO from pathlib import Path from typing import Any, Dict, List, Mapping, NoReturn, Optional, Tuple, Union @@ -114,14 +115,14 @@ async def storage_push(self, content: Mapping) -> str: resp.raise_for_status() return (await resp.json()).get("hash") - async def ipfs_push_file(self, file_content: Union[str, bytes]) -> str: + async def ipfs_push_file(self, file_content: bytes) -> str: """ Push a file to the IPFS service. :param file_content: The file content to upload """ data = aiohttp.FormData() - data.add_field("file", file_content) + data.add_field("file", BytesIO(file_content)) url = "/api/v0/ipfs/add_file" logger.debug(f"Pushing file to IPFS on {url}") @@ -135,7 +136,7 @@ async def storage_push_file(self, file_content) -> str: Push a file to the storage service. """ data = aiohttp.FormData() - data.add_field("file", file_content) + data.add_field("file", BytesIO(file_content)) url = "/api/v0/storage/add_file" logger.debug(f"Posting file on {url}") @@ -669,7 +670,7 @@ async def _storage_push_file_with_message( content_type="application/json", ) # Add the file - data.add_field("file", file_content) + data.add_field("file", BytesIO(file_content)) url = "/api/v0/storage/add_file" logger.debug(f"Posting file on {url}") From 978910d00af2787e7f18d894ca37d01fd09b71f9 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Wed, 19 Jun 2024 02:07:47 +0200 Subject: [PATCH 2/2] fix(authenticated_http/storage_push_file): fix and add type annotation --- src/aleph/sdk/client/authenticated_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aleph/sdk/client/authenticated_http.py b/src/aleph/sdk/client/authenticated_http.py index df4e4a35..60d42b2b 100644 --- a/src/aleph/sdk/client/authenticated_http.py +++ b/src/aleph/sdk/client/authenticated_http.py @@ -131,7 +131,7 @@ async def ipfs_push_file(self, file_content: bytes) -> str: resp.raise_for_status() return (await resp.json()).get("hash") - async def storage_push_file(self, file_content) -> str: + async def storage_push_file(self, file_content: bytes) -> Optional[str]: """ Push a file to the storage service. """