1
我在TeamCity上有一個使用自定義python腳本的構建步驟。當我嘗試運行構建我得到以下錯誤:Python請求超過url的最大重試次數
[20:57:12][Step 1/3] Traceback (most recent call last):
[20:57:12][Step 1/3] File "/amirsys/teamcity-agent/lastBuildStatus.py", line 24, in <module>
[20:57:12][Step 1/3] main()
[20:57:12][Step 1/3] File "/amirsys/teamcity-agent/lastBuildStatus.py", line 13, in main
[20:57:12][Step 1/3] build = getLastBuild(buildId)
[20:57:12][Step 1/3] File "/amirsys/teamcity-agent/teamcity.py", line 204, in getLastBuild
[20:57:12][Step 1/3] return requests.get(url, auth=auth)
[20:57:12][Step 1/3] File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
[20:57:12][Step 1/3] return request('get', url, **kwargs)
[20:57:12][Step 1/3] File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
[20:57:12][Step 1/3] return session.request(method=method, url=url, **kwargs)
[20:57:12][Step 1/3] File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 335, in request
[20:57:12][Step 1/3] resp = self.send(prep, **send_kwargs)
[20:57:12][Step 1/3] File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 438, in send
[20:57:12][Step 1/3] r = adapter.send(request, **kwargs)
[20:57:12][Step 1/3] File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 327, in send
[20:57:12][Step 1/3] raise ConnectionError(e)
[20:57:12][Step 1/3] requests.exceptions.ConnectionError: HTTPSConnectionPool(host='teamcity.amirsys-int.com', port=443): Max retries exceeded with url: /httpAuth/app/rest/builds/buildType:bt262,count:1 (Caused by <class 'socket.error'>: [Errno 110] Connection timed out)
我已經研究並發現,我認爲這可能是這裏的答案:Max retries exceeded with URL。他們建議使用:
from time import sleep
散佈請求間隔?這是我需要做的嗎?
我不明白我怎麼能發送過多的請求,因爲我的劇本只讓這個簡單的要求:
def getLastBuild(buildConfigId):
url = path + 'builds/buildType:' + buildConfigId + ',count:1'
return requests.get(url, auth=auth)
def main():
buildId = sys.argv[1]
build = getLastBuild(buildId)
if build.status_code == 200:
result = "SUCCESS"
print result
else:
result = "FAILURE"
print result
if __name__ == "__main__":
main()
這是爲什麼請求被拒絕?
如何調用'getLastBuild()'? – roganjosh
@roganjosh我用我的完整腳本更新了這個問題 –
嗯。在鏈接到你提出的答案鏈接到這個[問題](https://github.com/kennethreitz/requests/issues/1198)。由於您的代碼沒有指定任何重試嘗試,因此錯誤消息似乎沒有意義。你有沒有更新你的'requests'和'urllib3'(看起來他們建議你會得到一個更準確的「拒絕連接」,而不是「超過最大重試次數」來幫助固定它)? – roganjosh