|
23 | 23 | importitertools |
24 | 24 | importjson |
25 | 25 | importre |
| 26 | +importtime |
26 | 27 | importwarnings |
27 | 28 |
|
28 | 29 | importrequests |
@@ -698,24 +699,35 @@ def copy_dict(dest, src): |
698 | 699 | prepped.url=sanitized_url(prepped.url) |
699 | 700 | settings=self.session.merge_environment_settings( |
700 | 701 | prepped.url, {},streamed,verify,None) |
701 | | -result=self.session.send(prepped,timeout=timeout,**settings) |
702 | 702 |
|
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) |
705 | 705 |
|
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) |
719 | 731 |
|
720 | 732 | defhttp_get(self,path,query_data={},streamed=False,**kwargs): |
721 | 733 | """Make a GET request to the Gitlab server. |
|