Skip to content

Commit 29f2b31

Browse files
committed
Fix: aiohttp issues a DeprecationWarning
For passing bytes to a file upload instead of a BytesIO
1 parent 3e82f1d commit 29f2b31

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/aleph/sdk/client/authenticated_http.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import ssl
55
import time
6+
from io import BytesIO
67
from pathlib import Path
78
from typing import Any, Dict, List, Mapping, NoReturn, Optional, Tuple, Union
89

@@ -114,14 +115,14 @@ async def storage_push(self, content: Mapping) -> str:
114115
resp.raise_for_status()
115116
return (await resp.json()).get("hash")
116117

117-
async def ipfs_push_file(self, file_content: Union[str, bytes]) -> str:
118+
async def ipfs_push_file(self, file_content: bytes) -> str:
118119
"""
119120
Push a file to the IPFS service.
120121
121122
:param file_content: The file content to upload
122123
"""
123124
data = aiohttp.FormData()
124-
data.add_field("file", file_content)
125+
data.add_field("file", BytesIO(file_content))
125126

126127
url = "/api/v0/ipfs/add_file"
127128
logger.debug(f"Pushing file to IPFS on {url}")
@@ -135,7 +136,7 @@ async def storage_push_file(self, file_content) -> str:
135136
Push a file to the storage service.
136137
"""
137138
data = aiohttp.FormData()
138-
data.add_field("file", file_content)
139+
data.add_field("file", BytesIO(file_content))
139140

140141
url = "/api/v0/storage/add_file"
141142
logger.debug(f"Posting file on {url}")
@@ -669,7 +670,7 @@ async def _storage_push_file_with_message(
669670
content_type="application/json",
670671
)
671672
# Add the file
672-
data.add_field("file", file_content)
673+
data.add_field("file", BytesIO(file_content))
673674

674675
url = "/api/v0/storage/add_file"
675676
logger.debug(f"Posting file on {url}")

0 commit comments

Comments
 (0)