From 3958899c1905f0405f057a9ab9af268d10cbaa4e Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 3 Aug 2024 17:37:16 +0800 Subject: [PATCH] Add IncompleteRead --- curl_cffi/curl.py | 4 ++-- curl_cffi/requests/exceptions.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/curl_cffi/curl.py b/curl_cffi/curl.py index 12f7ff8..49659bd 100644 --- a/curl_cffi/curl.py +++ b/curl_cffi/curl.py @@ -2,7 +2,7 @@ import warnings from http.cookies import SimpleCookie from pathlib import Path -from typing import Any, List, Literal, Optional, Tuple, Union +from typing import Any, List, Literal, Optional, Tuple, Union, cast import certifi @@ -143,7 +143,7 @@ def _get_error(self, errcode: int, *args: Any): return CurlError( f"Failed to {action}, curl: ({errcode}) {errmsg}. " "See https://curl.se/libcurl/c/libcurl-errors.html first for more details.", - code=errcode, + code=cast(CurlECod, errcode), ) def setopt(self, option: CurlOpt, value: Any) -> int: diff --git a/curl_cffi/requests/exceptions.py b/curl_cffi/requests/exceptions.py index 09625c4..df35b99 100644 --- a/curl_cffi/requests/exceptions.py +++ b/curl_cffi/requests/exceptions.py @@ -44,6 +44,10 @@ class HTTPError(RequestException): """An HTTP error occurred.""" +class IncompleteRead(HTTPError): + """Incomplete read of content""" + + class ConnectionError(RequestException): """A Connection error occurred.""" @@ -201,6 +205,7 @@ class RequestsDependencyWarning(RequestsWarning): CurlECode.PROXY: ProxyError, CurlECode.SSL_CLIENTCERT: SSLError, CurlECode.ECH_REQUIRED: SSLError, + CurlECode.PARTIAL_FILE: IncompleteRead, }