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):
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.
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"))
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:
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.