No module named 'hubspot.auth'

Hello! Thanks for taking a time to help me!

I’m trying to use the module hubspot-api-client to do oauth authentication using python.

I’ve tried to follow the example code from GitHub - HubSpot/hubspot-api-python: HubSpot API Python Client Libraries for V3 version of the API · GitHub but when I run my code, I keep receiving this error

ModuleNotFoundError: No module named ‘hubspot.auth’

How could I fix this error?

Also, do you have any suggestion of a good quickbook to do Hubspot OAuth Auth?

Thanks!

Hi @LIntelligence and welcome to the Community!
It’s great to have you here!
Thanks for asking the Community!
I have found similar threads that might be of interest:
- No module named ‘hubspot.crm’ error when using ‘from hubspot.crm.deals import …’
- No module named ‘hubspot.crm’; ‘hubspot’ is not a package
- No module named ‘hubspot.crm.associations.batch’
I also wanted to invite a couple of subject matter experts to this conversation: Hi @Teun, @zach_threadint and @mangelet do you have suggestions to help @LIntelligence, please?
If anybody else has anything to add and/or share, please feel free to join in the conversation :slightly_smiling_face:
Thanks a lot and have a great day!
Best,
Bérangère

Hi @LIntelligence :waving_hand:

It could just be related to outdated or incorrect documentation, which I’ve found is quite common with the HubSpot API client libraries. Would you please share the Python code you’re currently using? Be sure to remove any potentially sensitive information (e.g. public app secrets etc.).

Hello Zach! How are you? Thanks for taking a time to help me!
Im just trying to do a very basic oAuth call

from hubspot.auth.oauth import ApiException

try:

tokens = api\_client.auth.oauth.tokens\_api.create(

    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)

Thanks for sharing that additional info @LIntelligence

I suspect the issue you’re experiencing may be related to the HubSpot Python Client Library version you’re using. The following code worked successfully in a test HubSpot Workflow custom code action, using “HubSpot Client v8”. It failed when trying with the other versions currently available (v7 and v4).

import os
from hubspot import HubSpot
from hubspot.auth.oauth import ApiException

def main(event):
 api_client = HubSpot(access_token=os.environ["pat"])

 try:
 tokens = api_client.auth.oauth.tokens_api.create(
 grant_type="authorization_code",
 redirect_uri="https://redirect.url",
 client_id=os.environ["app_client_id"],
 client_secret=os.environ["app_client_secret"],
 code="code",
 )
 print(tokens)
 except ApiException as e:
 print("Exception when calling create_token method: %s\n" % e)
 return {
 "outputFields": {
 "access_token": tokens["access_token"],
 "refresh_token": tokens["refresh_token"]
 }
 }

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