Skip to content

Commit

Permalink
Fix: aiohttp issues a DeprecationWarning (#129)
Browse files Browse the repository at this point in the history
For passing bytes to a file upload instead of a BytesIO

fix(authenticated_http/storage_push_file): fix and add type annotation

---------

Co-authored-by: Laurent Peuch <[email protected]>
  • Loading branch information
hoh and Psycojoker authored Jun 19, 2024
1 parent ac6a427 commit 1d3d5e5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/aleph/sdk/client/authenticated_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}")
Expand All @@ -130,12 +131,12 @@ async def ipfs_push_file(self, file_content: Union[str, 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.
"""
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}")
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 1d3d5e5

Please sign in to comment.