Skip to content

Commit 24015c9

Browse files
committed
server embedder - send bytes as content
1 parent 52cbdb0 commit 24015c9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Orange/misc/server_embedder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from functools import partial
99
from json import JSONDecodeError
1010
from os import getenv
11-
from typing import Any, Callable, List, Optional
11+
from typing import Any, Callable, List, Optional, Dict, Union
1212

1313
from AnyQt.QtCore import QSettings
1414
from httpx import AsyncClient, NetworkError, ReadTimeout, Response
@@ -306,7 +306,7 @@ async def _send_to_server(
306306
queue.task_done()
307307

308308
async def _send_request(
309-
self, client: AsyncClient, data: bytes, url: str
309+
self, client: AsyncClient, data: Union[bytes, Dict], url: str
310310
) -> Optional[List[float]]:
311311
"""
312312
This function sends a single request to the server.
@@ -331,7 +331,9 @@ async def _send_request(
331331
"Content-Length": str(len(data)),
332332
}
333333
try:
334-
response = await client.post(url, headers=headers, data=data)
334+
# bytes are sent as content parameter and dictionary as data
335+
kwargs = dict(content=data) if isinstance(data, bytes) else dict(data=data)
336+
response = await client.post(url, headers=headers, **kwargs)
335337
except ReadTimeout as ex:
336338
log.debug("Read timeout", exc_info=True)
337339
# it happens when server do not respond in time defined by timeout

Orange/misc/tests/test_server_embedder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ def __init__(self, content):
2727
def make_dummy_post(response):
2828
@staticmethod
2929
# pylint: disable=unused-argument
30-
async def dummy_post(url, headers, data):
30+
async def dummy_post(url, headers, content=None, data=None):
3131
# when sleeping some workers to still compute while other are done
3232
# it causes that not all embeddings are computed if we do not wait all
3333
# workers to finish
34+
assert (content is None) ^ (data is None)
3435
await asyncio.sleep(random() / 10)
3536
return DummyResponse(content=response)
3637

0 commit comments

Comments
 (0)