# Python issues with API connexion

**URL:** <https://community.hubspot.com/t/python-issues-with-api-connexion/57316>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [May 19, 2022, 4:01pm UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316 "2022-05-19T16:01:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CGuillo](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@CGuillo](https://community.hubspot.com/u/CGuillo)\
**Post date:** [May 19, 2022, 4:01pm UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316/1 "2022-05-19T16:01:55Z")

</div>

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](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

---

<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:** [May 19, 2022, 8:47pm UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316/2 "2022-05-19T20:47:43Z")

</div>

@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 😬🐍

---

<div class="post-metadata">

**Author:** ![KMurray](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kmurray/32/81360_2.png) [@KMurray](https://community.hubspot.com/u/KMurray)\
**Post date:** [May 20, 2022, 1:27am UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316/3 "2022-05-20T01:27:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CGuillo](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@CGuillo](https://community.hubspot.com/u/CGuillo)\
**Post date:** [May 20, 2022, 10:25am UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316/4 "2022-05-20T10:25:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sylvain\_tirreau](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sylvain_tirreau/32/67408_2.png) [@sylvain\_tirreau](https://community.hubspot.com/u/sylvain_tirreau)\
**Post date:** [November 17, 2023, 9:38am UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316/5 "2023-11-17T09:38:09Z")

</div>

Hi,

If you follow back Python Hubspot package source code, you’ll see the class Discovery (packages/hubspot/discovery/crm/contacts/discovery.py) has no “ **default\_api** ” method, but has a “ **basic\_api** ” one. I think the method name has changed since the redaction of API documentation.

So, If you write **api\_client.auth.oauth._basic\_api_.create\_token…** it will works.

Hope this help

---

<div class="post-metadata">

**Author:** ![NArtadi](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@NArtadi](https://community.hubspot.com/u/NArtadi)\
**Post date:** [November 28, 2023, 5:43pm UTC](https://community.hubspot.com/t/python-issues-with-api-connexion/57316/6 "2023-11-28T17:43:07Z")

</div>

Hi, if it helps, I changed default\_api to search\_api and it worked for me:

api\_response = client.crm.objects.notes.search\_api.do\_search(public\_object\_search\_request=public\_object\_search\_request)
