# ProtocolError

**URL:** <https://community.hubspot.com/t/protocolerror/98924>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [January 29, 2024, 8:01pm UTC](https://community.hubspot.com/t/protocolerror/98924 "2024-01-29T20:01:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmoccia](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pmoccia](https://community.hubspot.com/u/pmoccia)\
**Post date:** [January 29, 2024, 8:01pm UTC](https://community.hubspot.com/t/protocolerror/98924/1 "2024-01-29T20:01:10Z")

</div>

Hello, we wrote some python code in order to establish a connection to HubSpot in order to do an API request, but HubSpot itself or something in the middle of that connection is blocking/stopping the connection from even happening or as soon as it connects it just “closes” the connection blocking/stopping the connection from even happening or as soon as it connects it just “closes” the connection. Can you help here?

Here;s the error:

`[ERROR] ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))`

`Traceback (most recent call last):`

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [January 29, 2024, 11:20pm UTC](https://community.hubspot.com/t/protocolerror/98924/2 "2024-01-29T23:20:39Z")

</div>

Hi @pmoccia 👋

Would you please share the Python code that contains the HubSpot API request? This might help us get to the bottom of the issue you’re experiencing.

I hope this proves useful. Please let me know if you have any follow-up questions.

---

<div class="post-metadata">

**Author:** ![pmoccia](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pmoccia](https://community.hubspot.com/u/pmoccia)\
**Post date:** [January 30, 2024, 1:29pm UTC](https://community.hubspot.com/t/protocolerror/98924/3 "2024-01-30T13:29:16Z")

</div>

```auto
def get_contact_list_by_search(limit, regions):
 url = "https://api.hubapi.com/crm/v3/objects/contacts/search"
 headers = {
 "accept": "application/json",
 'Content-Type': 'application/json',
 "Authorization": f"Bearer {husbpot_token}",
 }
 filters = [
 {
 "values": [1,2,3],
 "propertyName": "autodialer_status",
 "operator": "IN"
 }
 ]
 # Only use the filter if regions array has entries
 if len(regions) != 0:
 filters.append({"values": regions,"propertyName": "region","operator": "IN"})
 payload = {
 "filterGroups": [
 {
 "filters": filters
 }
 ],
 "limit": limit,
 "properties":["id","firstname","lastname","email","phone","lead_source", "region","autodialer_status"],
 "sorts": ["autodialer_status"]
 }
 response = http.request('POST', url, headers=headers, body=json.dumps(payload).encode("UTF-8"))

```

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [January 30, 2024, 10:42pm UTC](https://community.hubspot.com/t/protocolerror/98924/4 "2024-01-30T22:42:33Z")

</div>

Hi @pmoccia 👋

I’m not familiar with the method in which you’re making HTTP requests there. If you haven’t already, you might like to consider using the “requests” module. For example:

```lia-code-sample
import json
import requests

def get_contact_list_by_search(limit, regions):
 url = "https://api.hubapi.com/crm/v3/objects/contacts/search"
 headers = {
 "Content-Type": "application/json",
 "Authorization": f"Bearer {husbpot_token}"
 }
 filters = [
 {
 "values": [1,2,3],
 "propertyName": "autodialer_status",
 "operator": "IN"
 }
 ]
 # Only use the filter if regions array has entries
 if len(regions) != 0:
 filters.append({"values": regions,"propertyName": "region","operator": "IN"})
 payload = {
 "filterGroups": [
 {
 "filters": filters
 }
 ],
 "limit": limit,
 "properties":["id","firstname","lastname","email","phone","lead_source", "region","autodialer_status"],
 "sorts": ["autodialer_status"]
 }
 response = requests.request("POST", url, headers=headers, data=json.dumps(payload).encode("UTF-8"))
 return response.text

print(get_contact_list_by_search(100, []))

```

Would you mind trying that to see if you’re still getting the same connection error?

I hope this proves useful. Please let me know if you have any follow-up questions.
