diff --git a/navigator/actions/rest.py b/navigator/actions/rest.py index 83f3bb3..5b8f0bd 100644 --- a/navigator/actions/rest.py +++ b/navigator/actions/rest.py @@ -342,7 +342,18 @@ async def process_request(self, future, url: str): result = filename # getting the result, based on the Accept logic elif self.file_buffer is True: - data = await response.read() + """ + Changed response.read() to response.content to fix the following error: + + Traceback (most recent call last): + File "/home/ubuntu/navigator-api/.venv/lib/python3.11/site-packages/navigator/actions/rest.py", line 345, in process_request + data = await response.read() + ^^^^^^^^^^^^^ + AttributeError: 'Response' object has no attribute 'read' + + During handling of the above exception, another exception occurred: + """ + data = response.content buffer = BytesIO(data) buffer.seek(0) result = buffer diff --git a/navigator/actions/zammad.py b/navigator/actions/zammad.py index a591705..cdcd4bc 100644 --- a/navigator/actions/zammad.py +++ b/navigator/actions/zammad.py @@ -13,6 +13,7 @@ ) from .ticket import AbstractTicket from .rest import RESTAction +from aiohttp.web import Response @@ -394,27 +395,18 @@ async def get_attachment_img(self, attachment: str): image, response = result - image_name = response.headers.get('Content-Disposition', 'attachment').split('=')[1].replace('"', '') - image_format = response.headers.get('Content-Type', 'image/png') - from aiohttp.web import StreamResponse - - response = StreamResponse( - status=200, - headers={ - 'Content-Type': image_format, - 'Content-Disposition': f'attachment; filename="{image_name}"', - 'Content-Length': str(len(image)), - 'Transfer-Encoding': 'chunked', - 'Connection': 'keep-alive', - 'Content-Description': 'File Transfer', - 'Content-Transfer-Encoding': 'binary' - } - ) - await response.prepare() - await response.write(image) - await response.write_eof() - return response - + # Obtener el tipo de contenido de la respuesta + + content_type = response.headers.get('Content-Type', 'application/octet-stream') + + # Devolver la imagen como respuesta HTTP + """ + Changed the return method to use web.Response instead of StreamResponse due to the following error: + + navigator.exceptions.exceptions: Error Getting Zammad Attachment: object of type '_io.BytesIO' has no len() + + Updated the headers and response handling to fix the issue. + """ + return Response(body=image, content_type=content_type) except Exception as e: raise ConfigError(f"Error Getting Zammad Attachment: {e}") from e -