APIs & Integrations

CGuillo
Member

Python issues with API connexion

SOLVE

Hi 🙂 

I have been trying to fetch data from Hubspot with Python and I am completely lost now. Hopefully someone can help 🙏

 

I have got the API key, created a test dev account, created an app, got the cliend id, the client secret, pip installed Hubspot in Anaconda and done this (code found in the documentation):

 

from hubspot import HubSpot
api_client = HubSpot(api_key='...')

from hubspot.auth.oauth import ApiException

try:
tokens = api_client.auth.oauth.default_api.create_token(
grant_type="authorization_code",
redirect_uri='http://localhost',
client_id='client_id',
client_secret='client_secret',
code='code'
)
except ApiException as e:
print("Exception when calling create_token method: %s\n" % e)

I am still missing the code that I have no idea how to find despite reading the documentation. AND I also get this error message which doesn't even seem linked to the missing code:

AttributeError: 'Discovery' object has no attribute 'default_api'

 
Can anyone help please? 
Thanks a lot! Corentin

0 Upvotes
1 Accepted solution
KMurray
Solution
Participant

Python issues with API connexion

SOLVE

I believe we are doing similar things.  If you are using Python, I also assume you are using the hubspot-client-api library.  

 

If so, I would use your test account and create a private app there.  Use the api and ability to accept the private app token.  Unless you are developing for the marketplace, I suggest to keep it simple and go the private app route in your test account and then move your code to a private app in the production account.  

 

my_token = 'pat-xxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

api_client = HubSpot()
api_client.access_token = my_token
 
Let me know how that works out for you.
 
Kevin

View solution in original post

3 Replies 3
CGuillo
Member

Python issues with API connexion

SOLVE

Hi Kevin, Hi Dennis,

thanks a lot for answering! 

 

I did what you suggested @KMurray and I don't have an error message when doing so! 🙂 
BUT When I try to call, for example: 

api_client.crm.contacts.get_all()

I get an error message 😞 

MaxRetryError: HTTPSConnectionPool(host='api.hubapi.com', port=443): Max retries exceeded with url: /crm/v3/objects/contacts?limit=100 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

 

Any idea on what I am doing wrong here?

 

Thanks again! 🙏

Corentin

0 Upvotes
KMurray
Solution
Participant

Python issues with API connexion

SOLVE

I believe we are doing similar things.  If you are using Python, I also assume you are using the hubspot-client-api library.  

 

If so, I would use your test account and create a private app there.  Use the api and ability to accept the private app token.  Unless you are developing for the marketplace, I suggest to keep it simple and go the private app route in your test account and then move your code to a private app in the production account.  

 

my_token = 'pat-xxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

api_client = HubSpot()
api_client.access_token = my_token
 
Let me know how that works out for you.
 
Kevin
dennisedson
Community Manager
Community Manager

Python issues with API connexion

SOLVE

@JBeatty  is a smart fellow and I think might be the right person to help you out here

Also, how do we feel about all the snake references in python 😬🐍

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes