Skip to content
Advertisement

REST API: How to prevent “An existing connection was forcibly closed by the remote host”

Following this thread, https://stackoverflow.com/a/2582070/6534818, I am wondering if there is any room for improvement to my REST API query that would limit the frequency to which I receive the following error: "An existing connection was forcibly closed by the remote host". The thread suggests, as one possibility, that the query is malformed.

My general setup for a query to Azure DevOps is as follows:

# Access Token
pat = "secret_token_here"

# authorization encoding
authorization = str(base64.b64encode(bytes(":" + pat, "ascii")), "ascii")

# url
url = "https://dev.azure.com/org/project/"

# REST headers
headers = {"Accept": "application/json", "Authorization": "Basic " + authorization}

# GET
response = requests.get(
    url=(url + "_apis/wit/workItems/%s/revisions?api-version=6.0" % str(work_item)),
    headers=headers,
)

I tend to suffer this issue when running this in a loop, perhaps every 4th or 5th total run, looking up each item of interest.

Advertisement

Answer

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement