File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,14 @@ def request(
212212
213213 lgr .debug ("%s %s" , method .upper (), url )
214214
215+ def _rewind_data (retry_state : tenacity .RetryCallState ) -> None :
216+ # After a failed attempt (ConnectionError mid-upload, HTTPError,
217+ # etc.), the file pointer may be at an arbitrary position. Seek
218+ # back to 0 so the next attempt sends the complete body.
219+ # See https://github.com/dandi/dandi-cli/issues/1821
220+ if data is not None and hasattr (data , "seek" ):
221+ data .seek (0 )
222+
215223 try :
216224 for i , attempt in enumerate (
217225 tenacity .Retrying (
@@ -225,6 +233,7 @@ def request(
225233 ),
226234 stop = tenacity .stop_after_attempt (REQUEST_RETRIES ),
227235 reraise = True ,
236+ before_sleep = _rewind_data ,
228237 )
229238 ):
230239 with attempt :
@@ -249,8 +258,6 @@ def request(
249258 url ,
250259 result .text ,
251260 )
252- if data is not None and hasattr (data , "seek" ):
253- data .seek (0 )
254261 if retry_after := get_retry_after (result ):
255262 lgr .debug (
256263 "Sleeping for %d seconds as instructed in response "
You can’t perform that action at this time.
0 commit comments