APIs & Integrations

AApollis
Member

Error Connecting via Apps using Python

SOLVE

 

I am getting this error below when trying to connect to Hubspot using a private app created and Python.

"

Traceback (most recent call last):
File "C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in
loads
return _default_decoder.decode(s)
File "C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Anthony.DESKTOP-ES5HL78\Documents\Scrapy\projects\auth.py", line 22, in <module>
auth_token = get_auth_token()
File "C:\Users\Anthony.DESKTOP-ES5HL78\Documents\Scrapy\projects\auth.py", line 15, in get_auth_token
response_dict = response.json()
File "C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

" AND

"Error getting access token: b'{"status":"BAD_GRANT_TYPE","message":"missing or unknown grant type","correlationId":"daab6538-15f6-4e5a-8172-c70ed3ef3376"}'
Error getting access token: b'{"status":"BAD_GRANT_TYPE","message":"missing or unknown grant type","correlationId":"6c614382-cf20-47a0-827a-c48c7ac47056"}'
Error getting access token: b'{"status":"BAD_GRANT_TYPE","message":"missing or unknown grant type","correlationId":"f3d91db5-1610-4b69-856a-d9ff16a7acee"}'
Error getting acce"

Here is my code: "

import requests

CLIENT_ID = 'e2e6713e-0813-457a-b2c2-19ff2df1407c'
CLIENT_SECRET = '9b876b6e-835b-40ba-b48e-216010ce00ea'
ACCESS_TOKEN = 'i provided access code as per app created'

def get_auth_token():
    data = {
        'grant_type': 'client_credentials',
        'client_id': CLIENT_ID,
        'client_secret': CLIENT_SECRET
    }
    response = requests.post(url, data=data)
    response_dict = response.json()
    if 'access_token' in response_dict:
        return response_dict['access_token']
    else:
        print(f"Error: {response_dict.get('error_description')}")
        return None

auth_token = get_auth_token()
if auth_token:
    print(auth_token)
else:
    print("Could not retrieve authentication token.")

"

Please assist?

0 Upvotes
1 Accepted solution
andreaska
Solution
Participant

Error Connecting via Apps using Python

SOLVE

Hi!

 

1. I think you need to check your URL because it currently contains your private app API key

2. You need to encode your POST request data as json

 

import json

url = "" # check your correct API URL here
data = {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET
}
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, data=json.dumps(data), headers=headers)

 

Cheers,

Andreas

View solution in original post

0 Upvotes
5 Replies 5
AApollis
Member

Error Connecting via Apps using Python

SOLVE

PowerBI and Tableau do not have an integrated connector to Hubspot. I want to build a Python data pipeline to extract data from Hubspot into a SQL DB to connect to BI reporting tools. Please advise.

0 Upvotes
andreaska
Solution
Participant

Error Connecting via Apps using Python

SOLVE

Hi!

 

1. I think you need to check your URL because it currently contains your private app API key

2. You need to encode your POST request data as json

 

import json

url = "" # check your correct API URL here
data = {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET
}
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, data=json.dumps(data), headers=headers)

 

Cheers,

Andreas

0 Upvotes
AApollis
Member

Error Connecting via Apps using Python

SOLVE

I am getting an error even without the URL, how would I incorporate your code into mine?

0 Upvotes
andreaska
Participant

Error Connecting via Apps using Python

SOLVE

Hi, 

I think we need to go back on step. What do you try to achieve with your code. It looks like at the moment, Hubspot does not support the client_credentails auth flow. It is only possible to authenticate via an HTTP redirect. 

 

Please review the Working with OAuth documentation.

 

Cheers,

Andreas

 

0 Upvotes
AApollis
Member

Error Connecting via Apps using Python

SOLVE

PowerBI and Tableau does not have an integrated connector to Hubspot. I would like to build a data pipeline using Python to extract data from Hubspot into a SQL db to be able to connect to BI reporting tools. Please advice.

0 Upvotes