Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2abf9ab

Browse files
committed
feat: obey the rate limit
done by using the retry-after headerFixes#166
1 parent25ed8e7 commit2abf9ab

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

‎gitlab/__init__.py‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
importitertools
2424
importjson
2525
importre
26+
importtime
2627
importwarnings
2728

2829
importrequests
@@ -698,24 +699,35 @@ def copy_dict(dest, src):
698699
prepped.url=sanitized_url(prepped.url)
699700
settings=self.session.merge_environment_settings(
700701
prepped.url, {},streamed,verify,None)
701-
result=self.session.send(prepped,timeout=timeout,**settings)
702702

703-
if200<=result.status_code<300:
704-
returnresult
703+
# obey the rate limit by default
704+
obey_rate_limit=kwargs.get("obey_rate_limit",True)
705705

706-
try:
707-
error_message=result.json()['message']
708-
except (KeyError,ValueError,TypeError):
709-
error_message=result.content
710-
711-
ifresult.status_code==401:
712-
raiseGitlabAuthenticationError(response_code=result.status_code,
713-
error_message=error_message,
714-
response_body=result.content)
715-
716-
raiseGitlabHttpError(response_code=result.status_code,
717-
error_message=error_message,
718-
response_body=result.content)
706+
whileTrue:
707+
result=self.session.send(prepped,timeout=timeout,**settings)
708+
709+
if200<=result.status_code<300:
710+
returnresult
711+
712+
if429==result.status_codeandobey_rate_limit:
713+
wait_time=int(result.headers["Retry-After"])
714+
time.sleep(wait_time)
715+
continue
716+
717+
try:
718+
error_message=result.json()['message']
719+
except (KeyError,ValueError,TypeError):
720+
error_message=result.content
721+
722+
ifresult.status_code==401:
723+
raiseGitlabAuthenticationError(
724+
response_code=result.status_code,
725+
error_message=error_message,
726+
response_body=result.content)
727+
728+
raiseGitlabHttpError(response_code=result.status_code,
729+
error_message=error_message,
730+
response_body=result.content)
719731

720732
defhttp_get(self,path,query_data={},streamed=False,**kwargs):
721733
"""Make a GET request to the Gitlab server.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp