diff --git a/src/urlscan/client.py b/src/urlscan/client.py index 73957a0..d17b37f 100644 --- a/src/urlscan/client.py +++ b/src/urlscan/client.py @@ -237,7 +237,7 @@ def _send_request( utcnow = datetime.datetime.now(datetime.timezone.utc) if rate_limit.remaining == 0 and rate_limit.reset > utcnow: raise RateLimitRemainingError( - f"{action} is rate limited. Wait until {utcnow}." + f"{action} is rate limited. Wait until {rate_limit.reset}." ) res = ClientResponse(session.send(request)) diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 7f6e8ee..c031c0c 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -240,6 +240,32 @@ def handler(_: Request): client.get_result("dummy") +@pytest.mark.freeze_time("2020-01-01") +def test_rate_limit_remaining_error_message(client: Client, httpserver: HTTPServer): + httpserver.expect_request( + "/api/v1/result/dummy/", + method="GET", + ).respond_with_response( + Response( + "{}", + status=200, + headers={ + "X-Rate-Limit-Action": "retrieve", + "X-Rate-Limit-Remaining": "0", + "X-Rate-Limit-Reset": "2020-01-02T00:00:00.000Z", + }, + ) + ) + + assert client.get_result("dummy") is not None + # the message should contain the reset time, not the current time + with pytest.raises( + RateLimitRemainingError, + match=r"Wait until 2020-01-02 00:00:00\+00:00", + ): + client.get_result("dummy") + + def test_scan(client: Client, httpserver: HTTPServer): httpserver.expect_request( "/api/v1/scan/",