Skip to content

Commit e558775

Browse files
committed
Add HTTPTooManyRequestsError, closes #2267
1 parent 76ed4be commit e558775

5 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Fixes:
3636
- Add ``cython.final`` to leaf classes, ensuring that they are not subclassed.
3737
- Warn that ``CodecContext.decode()`` is not memory safe in some cases.
3838
- Fix ``enumerate_input_devices`` and ``enumerate_output_devices`` raising ``AttributeError`` (:issue:`2264`).
39+
- Map HTTP 429 to ``HTTPTooManyRequestsError`` instead of ``UndefinedError`` (:issue:`2267`).
3940

4041
v17.0.1
4142
-------

‎av/error.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class HTTPClientError(FFmpegError):
161161
("HTTP_UNAUTHORIZED", -lib.AVERROR_HTTP_UNAUTHORIZED, "HTTPUnauthorizedError", HTTPClientError),
162162
("HTTP_FORBIDDEN", -lib.AVERROR_HTTP_FORBIDDEN, "HTTPForbiddenError", HTTPClientError),
163163
("HTTP_NOT_FOUND", -lib.AVERROR_HTTP_NOT_FOUND, "HTTPNotFoundError", HTTPClientError),
164+
("HTTP_TOO_MANY_REQUESTS", -lib.AVERROR_HTTP_TOO_MANY_REQUESTS, "HTTPTooManyRequestsError", HTTPClientError),
164165
("HTTP_OTHER_4XX", -lib.AVERROR_HTTP_OTHER_4XX, "HTTPOtherClientError", HTTPClientError),
165166
("HTTP_SERVER_ERROR", -lib.AVERROR_HTTP_SERVER_ERROR, "HTTPServerError", HTTPError),
166167
("PYAV_CALLBACK", c_PYAV_STASHED_ERROR, "PyAVCallbackError", RuntimeError),

‎av/error.pyi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class HTTPBadRequestError(HTTPClientError): ...
4646
class HTTPUnauthorizedError(HTTPClientError): ...
4747
class HTTPForbiddenError(HTTPClientError): ...
4848
class HTTPNotFoundError(HTTPClientError): ...
49+
class HTTPTooManyRequestsError(HTTPClientError): ...
4950
class HTTPOtherClientError(HTTPClientError): ...
5051
class HTTPServerError(HTTPError): ...
5152
class PyAVCallbackError(FFmpegError, builtins.RuntimeError): ...

‎include/avutil.pxd‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ cdef extern from "libavutil/error.h" nogil:
172172
cdef int AVERROR_HTTP_UNAUTHORIZED
173173
cdef int AVERROR_HTTP_FORBIDDEN
174174
cdef int AVERROR_HTTP_NOT_FOUND
175+
cdef int AVERROR_HTTP_TOO_MANY_REQUESTS
175176
cdef int AVERROR_HTTP_OTHER_4XX
176177
cdef int AVERROR_HTTP_SERVER_ERROR
177178
cdef int AV_ERROR_MAX_STRING_SIZE

‎tests/test_errors.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,16 @@ def test_buffertoosmall() -> None:
6363
assert e.errno == BUFFER_TOO_SMALL
6464
else:
6565
assert False, "No exception raised!"
66+
67+
68+
def test_http_too_many_requests() -> None:
69+
"""HTTP 429 maps to HTTPTooManyRequestsError, not UndefinedError."""
70+
71+
HTTP_TOO_MANY_REQUESTS = av.error.tag_to_code(b"\xf8429")
72+
try:
73+
av.error.err_check(-HTTP_TOO_MANY_REQUESTS)
74+
except av.error.HTTPTooManyRequestsError as e:
75+
assert e.errno == HTTP_TOO_MANY_REQUESTS
76+
assert isinstance(e, av.error.HTTPClientError)
77+
else:
78+
assert False, "No exception raised!"

0 commit comments

Comments
 (0)