@@ -72,15 +72,31 @@ def create_client(
7272 follow_redirects : bool = True ,
7373) -> httpx .Client :
7474 """Factory for a configured httpx.Client."""
75- return httpx .Client (
76- headers = _default_headers (headers ),
77- cookies = cookies ,
78- timeout = timeout if timeout is not None else _get_timeout (),
79- verify = _get_verify () if verify is None else verify ,
80- follow_redirects = follow_redirects ,
81- http2 = http2 ,
82- proxy = proxies if proxies is not None else _get_proxies (),
83- )
75+ proxy_value = proxies if proxies is not None else _get_proxies ()
76+
77+ # Try with 'proxy' first (older httpx versions)
78+ try :
79+ return httpx .Client (
80+ headers = _default_headers (headers ),
81+ cookies = cookies ,
82+ timeout = timeout if timeout is not None else _get_timeout (),
83+ verify = _get_verify () if verify is None else verify ,
84+ follow_redirects = follow_redirects ,
85+ http2 = http2 ,
86+ proxy = proxy_value ,
87+ )
88+
89+ except TypeError :
90+ # Fall back to 'proxies' (newer httpx versions >= 0.24.0)
91+ return httpx .Client (
92+ headers = _default_headers (headers ),
93+ cookies = cookies ,
94+ timeout = timeout if timeout is not None else _get_timeout (),
95+ verify = _get_verify () if verify is None else verify ,
96+ follow_redirects = follow_redirects ,
97+ http2 = http2 ,
98+ proxies = proxy_value ,
99+ )
84100
85101
86102def create_async_client (
@@ -94,15 +110,31 @@ def create_async_client(
94110 follow_redirects : bool = True ,
95111) -> httpx .AsyncClient :
96112 """Factory for a configured httpx.AsyncClient."""
97- return httpx .AsyncClient (
98- headers = _default_headers (headers ),
99- cookies = cookies ,
100- timeout = timeout if timeout is not None else _get_timeout (),
101- verify = _get_verify () if verify is None else verify ,
102- follow_redirects = follow_redirects ,
103- http2 = http2 ,
104- proxies = proxies if proxies is not None else _get_proxies (),
105- )
113+ proxy_value = proxies if proxies is not None else _get_proxies ()
114+
115+ # Try with 'proxy' first (older httpx versions)
116+ try :
117+ return httpx .AsyncClient (
118+ headers = _default_headers (headers ),
119+ cookies = cookies ,
120+ timeout = timeout if timeout is not None else _get_timeout (),
121+ verify = _get_verify () if verify is None else verify ,
122+ follow_redirects = follow_redirects ,
123+ http2 = http2 ,
124+ proxy = proxy_value ,
125+ )
126+
127+ except TypeError :
128+ # Fall back to 'proxies' (newer httpx versions >= 0.24.0)
129+ return httpx .AsyncClient (
130+ headers = _default_headers (headers ),
131+ cookies = cookies ,
132+ timeout = timeout if timeout is not None else _get_timeout (),
133+ verify = _get_verify () if verify is None else verify ,
134+ follow_redirects = follow_redirects ,
135+ http2 = http2 ,
136+ proxies = proxy_value ,
137+ )
106138
107139
108140def create_client_curl (
@@ -226,4 +258,4 @@ async def async_fetch(
226258 break
227259 # Use same backoff logic for async by sleeping in thread (short duration)
228260 _sleep_with_backoff (attempt )
229- return None
261+ return None
0 commit comments