uplink icon indicating copy to clipboard operation
uplink copied to clipboard

Asyncio binary response is being decoded forcefully

Open KDanisme opened this issue 2 years ago • 0 comments

Describe the bug When using the asyncio client session and getting a binary response, uplink crashes due to trying to decode it.

To Reproduce Define a method that has a response that contains a binary value

@get("/some-binary-file")
def get_binary(self): pass

call await get_binary()

Expected behavior get an aiohttp.ClientResponse that contains a bytes object

Actual behavior

Traceback (most recent call last):
  File "uplink/clients/io/asyncio_strategy.py", line 32, in execute
    return await executable.execute()
  File "uplink/clients/io/asyncio_strategy.py", line 21, in invoke
    response = await callback.on_success(response)
  File "uplink/clients/io/asyncio_strategy.py", line 19, in invoke
    response = await callback.on_failure(type(error), error, tb)
  File "uplink/clients/io/execution.py", line 108, in on_failure
    return self._io.fail(exc_type, exc_val, exc_tb)
  File "uplink/clients/io/interfaces.py", line 300, in fail
    compat.reraise(exc_type, exc_val, exc_tb)
  File "six.py", line 719, in reraise
    raise value
  File "uplink/clients/io/asyncio_strategy.py", line 16, in invoke
    response = await func(*args, **kwargs)
  File "uplink/clients/aiohttp_.py", line 25, in new_callback
    await response.text()
  File "aiohttp/client_reqrep.py", line 1085, in text
    return self._body.decode(  # type: ignore[no-any-return,union-attr]
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xac in position 10: invalid start byte

Additional context I realise there's a await response.text in File "uplink/clients/aiohttp_.py", line 25, in new_callback which i presume awaits the response inorder to wrap it or something, i simply replaced it with response.read() which gets the response without trying to decode it, and it worked.

KDanisme avatar Oct 21 '22 21:10 KDanisme