Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openmeteo_requests/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def _process_response(
total = len(data)
pos, step = 0, 4
while pos < total:
length = int.from_bytes(data[pos : pos + step], byteorder="little")
# In stream error messages start with "Unexpected"
if length == 0x78656E55:
raise OpenMeteoRequestsError(data[pos:total].decode("utf-8"))
message = handler.GetRootAs(data, pos + step)
messages.append(message)
length = int.from_bytes(data[pos : pos + step], byteorder="little")
pos += length + step
return messages

Expand Down
13 changes: 12 additions & 1 deletion tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from typing import Any

import pytest
from niquests import AsyncSession, Session
from niquests import AsyncSession, Response, Session
from openmeteo_sdk.Variable import Variable

from openmeteo_requests import AsyncClient, Client, OpenMeteoRequestsError
from openmeteo_requests.Client import _process_response


def _process_fetchall_basic_responses(responses: list) -> None:
Expand Down Expand Up @@ -99,6 +100,16 @@ def test_sequential_requests_with_common_session(self, url: str, params: _Params
# with pytest.raises(OpenMeteoRequestsError):
_process_fetchall_basic_responses(client.weather_api(url=url, params=params))

def test_error_stream(
self,
) -> None:
response = Response()
# ruff: noqa: SLF001
response._content = b"Unexpected error while streaming data: timeoutReached"
with pytest.raises(OpenMeteoRequestsError) as error:
_process_response(response)
assert str(error.value) == "Unexpected error while streaming data: timeoutReached"


@pytest.mark.asyncio
class TestAsyncClient:
Expand Down