@@ -638,11 +638,23 @@ def max_attempts(self, value: int) -> None:
638638 if value == 1 : # No retry
639639 self ._get = self ._http_session .get
640640 self ._post = self ._http_session .post
641+ self ._get_statement = self ._http_session .get
642+ self ._post_statement = self ._http_session .post
641643 self ._delete = self ._http_session .delete
642644 self ._head = self ._http_session .head
643645 return
644646
645647 with_retry = _retry_with (
648+ self ._handle_retry ,
649+ handled_exceptions = self ._exceptions ,
650+ conditions = (
651+ # need retry when there is no exception but the status code is 429, 502, 503, or 504
652+ lambda response : getattr (response , "status_code" , None )
653+ in (429 , 502 , 503 , 504 ),
654+ ),
655+ max_attempts = self ._max_attempts ,
656+ )
657+ with_statement_retry = _retry_with (
646658 self ._handle_retry ,
647659 handled_exceptions = self ._exceptions ,
648660 conditions = (
@@ -651,12 +663,14 @@ def max_attempts(self, value: int) -> None:
651663 in (429 , 502 , 503 , 504 ),
652664 # need retry when the server returns 200 with an empty body (transient under load)
653665 lambda response : getattr (response , "status_code" , None ) == 200
654- and not getattr (response , "text " , "" ). strip ( ),
666+ and not getattr (response , "content " , b"" ),
655667 ),
656668 max_attempts = self ._max_attempts ,
657669 )
658670 self ._get = with_retry (self ._http_session .get )
659671 self ._post = with_retry (self ._http_session .post )
672+ self ._get_statement = with_statement_retry (self ._http_session .get )
673+ self ._post_statement = with_statement_retry (self ._http_session .post )
660674 self ._delete = with_retry (self ._http_session .delete )
661675 self ._head = with_retry (self ._http_session .head )
662676
@@ -686,7 +700,7 @@ def post(self, sql: str, additional_http_headers: Optional[Dict[str, Any]] = Non
686700 # explicitly to match the Trino JDBC client. Users may still override it.
687701 http_headers .setdefault (constants .HEADER_CONTENT_TYPE , constants .CONTENT_TYPE_TEXT_UTF8 )
688702
689- http_response = self ._post (
703+ http_response = self ._post_statement (
690704 self .statement_url ,
691705 data = data ,
692706 headers = http_headers ,
@@ -696,7 +710,7 @@ def post(self, sql: str, additional_http_headers: Optional[Dict[str, Any]] = Non
696710 return http_response
697711
698712 def get (self , url : str ) -> Response :
699- return self ._get (
713+ return self ._get_statement (
700714 url ,
701715 headers = self .http_headers ,
702716 timeout = self ._request_timeout ,
0 commit comments