Python requests max retries exceeded with url

我怕爱的太早我们不能终老 提交于 2019-12-11 07:57:19

问题


I have a build step on TeamCity that uses a custom python script. When I try to run the build I get the following error:

[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)

I have researched and found an answer that I think it could be here: Max retries exceeded with URL. They suggest using:

from time import sleep

to spread out the request interval? Is this what I need to do?

I don't understand how I can be sending too many requests as my script only makes this simple request:

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()

Why is this request refused?


回答1:


I finally figured out what the problem was. The request was accessing a url by leaving the local host and couldn't "get back in" so the connection timed out. This was fixed by providing the correct IP address.



来源:https://stackoverflow.com/questions/40369050/python-requests-max-retries-exceeded-with-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!