# API Contacts: Remote end closed connection without response

**URL:** <https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [January 16, 2022, 2:49am UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852 "2022-01-16T02:49:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![camera](https://avatars.discourse-cdn.com/v4/letter/c/b782af/32.png) [@camera](https://community.hubspot.com/u/camera)\
**Post date:** [January 16, 2022, 2:49am UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/1 "2022-01-16T02:49:15Z")

</div>

Hello people!

I’m doing some requests to the Contacts endpoint to get all of my contacts. But, sometimes I get an error that I can’t handle. I think that the server isn’t responding to my request.

There are a lot of contacts (700k) and I’m running the code below in a for iteration.

I know about the rate limits, and I’m sure I’m not passing thru.

```lia-code-sample
url = 'https://api.hubapi.com/crm/v3/objects/contacts'

headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + <token>
}

params = {
'limit': 100,
'properties': <list of properties>,
'after': <next_paging number>
}

response = requests.get(url=url, headers=headers, params=params)

```

Sometimes I get the error below, sometimes I don’t.

```lia-code-sample
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

http.client.RemoteDisconnected: Remote end closed connection without response

urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

```

I’ve summarized the error so it doesn’t get too big.

Can anyone help me, please?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [January 18, 2022, 4:17pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/2 "2022-01-18T16:17:33Z")

</div>

@camera

From my searches, this appears to be a python bug perhaps 🤔

@JBeatty , @BJacobson either of you run into this before?

---

<div class="post-metadata">

**Author:** ![camera](https://avatars.discourse-cdn.com/v4/letter/c/b782af/32.png) [@camera](https://community.hubspot.com/u/camera)\
**Post date:** [January 20, 2022, 5:59pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/3 "2022-01-20T17:59:27Z")

</div>

Hi @dennisedson !

Thanks for reply! It’s not a python bug. It’s about the non-response of some messages by Hubspot’s API server.

I made some improvements in the API request in the python script. I configured the retry factor from the urllib3 library ([https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry](https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry)) and now my pipeline it’s not crashing anymore.

But, even so, I would like to know why the Hubspot API server is not answer some of my requests…

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![SBurwash](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@SBurwash](https://community.hubspot.com/u/SBurwash)\
**Post date:** [August 24, 2022, 7:15pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/4 "2022-08-24T19:15:58Z")

</div>

I came accross this issue also; would there be a way to solve it? Our syncs take a long time since we need to iterate through all of our associations, and this is making our ETL tool fail

---

<div class="post-metadata">

**Author:** ![RubenBurdin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rubenburdin/32/75212_2.png) [@RubenBurdin](https://community.hubspot.com/u/RubenBurdin)\
**Post date:** [April 1, 2025, 2:45pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/5 "2025-04-01T14:45:39Z")

</div>

I had the same issue when building our syncs. In custom-code, we had to implement retries (ideally retry 4 times at intervals of 5 seconds). It is possible that the issue still persists after 4 retries altough most case should pass with this simple rule.

Since our data was massive and we had to iterate over 200k+ Associations too, we just ended up using Stacksync managed two-way sync with our database (postgres) and it has never failed so far. They manage this issue internally.

---

<div class="post-metadata">

**Author:** ![GAlinio](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@GAlinio](https://community.hubspot.com/u/GAlinio)\
**Post date:** [October 14, 2024, 6:10pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/6 "2024-10-14T18:10:57Z")

</div>

I’m encountering the same issue today:

`ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))`

Even after using the provided sample from here: [sample-apps-retry-middleware/python/cli.py at main · HubSpot/sample-apps-retry-middleware · GitHub](https://github.com/HubSpot/sample-apps-retry-middleware/blob/main/python/cli.py), the error persists, particularly with status 429 or “RemoteDisconnected.”

Here’s my code:

```lia-code-sample
from urllib3.util import Retry
from requests.adapters import HTTPAdapter
import requests
from hubspot import HubSpot

# Create a HubSpot client with retry logic
def create_client(api_key):
 # Set interval based on environment
 if environment == "sb": # Sandbox
 interval = 6 # 6 seconds for free plan
 else: # Production
 interval = 1 # 1 second for pro plan

 # Define the retry strategy
 retry_strategy = Retry(
 total=5, # Total number of retries
 backoff_factor=interval, # Exponential backoff
 status_forcelist=[429, 500, 502, 504], # Status codes to retry
 allowed_methods=["HEAD", "GET", "OPTIONS", "POST", "PUT"], # Methods for retry
 raise_on_status=False # Don't raise error after final retry
 )

 # Create an HTTP adapter with the retry strategy
 adapter = HTTPAdapter(max_retries=retry_strategy)

 # Create a session and mount the adapter
 http = requests.Session()
 http.mount("https://", adapter)
 http.mount("http://", adapter)

 # Update session headers with API token
 http.headers.update(
 {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"}
 )

 return HubSpot(access_token=api_key, http=http)

# Create HubSpot API clients for different calls
api_client_companies = create_client(get_access_token("HUBSPOT_COMPANIES", "companies"))
api_client_contacts = create_client(get_access_token("HUBSPOT_CONTACTS", "contacts"))

```

Could anyone share insights or suggest further improvements? Thank you!

---

<div class="post-metadata">

**Author:** ![RubenBurdin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rubenburdin/32/75212_2.png) [@RubenBurdin](https://community.hubspot.com/u/RubenBurdin)\
**Post date:** [February 3, 2025, 6:31pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/7 "2025-02-03T18:31:11Z")

</div>

This article solved it for me [Explaining Hubspot's RemoteDisconnected error | Stacksync](https://www.stacksync.com/blog/explaining-hubspots-remotedisconnected-error)

---

<div class="post-metadata">

**Author:** ![RubenBurdin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rubenburdin/32/75212_2.png) [@RubenBurdin](https://community.hubspot.com/u/RubenBurdin)\
**Post date:** [October 14, 2024, 6:58pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/8 "2024-10-14T18:58:52Z")

</div>

Hey there,

Founder at Stacksync here. _ **RemoteDisconnected** _ is a common HubSpot error that can happen for a variety of reasons, coming due to HubSpot issues (most often) or sometimes network issues depending on how reliable is your cloud provider and network tier.

At Stacksync, we have several parallel data read/write processed for a single HubSpot instance. We have implemented a retry module on the API call with exponential backoff delays. It ensures that you do not exceed rate limits, as well as being robust to repeated _ **RemoteDisconnected** _ errors (the error can happen sometimes 1-4 times in a row, and this can lead to coordination issues between processes if you parallellize queries).

For context, Stacksync powers real-time and bidirectional sync between HubSpot and Databases like Postgres, Snowflake, BigQuery, MySQL and more.

---

<div class="post-metadata">

**Author:** ![GAlinio](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@GAlinio](https://community.hubspot.com/u/GAlinio)\
**Post date:** [October 14, 2024, 9:01pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/9 "2024-10-14T21:01:17Z")

</div>

Hi @RubenBurdin,

Thank you for your response about the RemoteDisconnected error in HubSpot. I appreciate the information on how Stacksync handles parallel data processing and the retry module. It’s very helpful for improving my script. I have a few quick questions:

1. Can you share more details about how you implemented the retry module? Any best practices or specific libraries you recommend?
2. Could you provide examples of how you manage rate limits effectively in a high-volume environment?

I look forward to using these strategies in my setup.

Thanks again!  
Gerald

---

<div class="post-metadata">

**Author:** ![RubenBurdin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rubenburdin/32/75212_2.png) [@RubenBurdin](https://community.hubspot.com/u/RubenBurdin)\
**Post date:** [October 16, 2024, 9:46pm UTC](https://community.hubspot.com/t/api-contacts-remote-end-closed-connection-without-response/49852/10 "2024-10-16T21:46:42Z")

</div>

Hey @GAlinio,

Unsure I fully understand the question here. Would you like to see code or architecture?

Happy to chat about it at [https://cal.com/rubenburdin/20min](https://cal.com/rubenburdin/20min) (feel free to book anytime) if you wanna deep dive together into the topic.

Cheers,
