1

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?

Community
  • 1
  • 1
fractalflame
  • 1,011
  • 1
  • 9
  • 20
  • How do you call `getLastBuild()`? – roganjosh Nov 01 '16 at 21:39
  • @roganjosh I updated the question with my full script – fractalflame Nov 01 '16 at 21:47
  • Hmm. Following the link to your proposed answer links to this [issue](https://github.com/kennethreitz/requests/issues/1198). Since your code doesn't specify any retry attempts then the error message doesn't appear to make sense. Have you updated your `requests` and `urllib3` (it appears they suggest that you will get a more accurate "connection refused" rather than "max retries exceeded" to help pin it down)? – roganjosh Nov 01 '16 at 22:05
  • @roganjosh yes I have updated them. – fractalflame Nov 02 '16 at 14:18

1 Answers1

0

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.

fractalflame
  • 1,011
  • 1
  • 9
  • 20