python login no longer working
I have been using the python zcrmsdk module over the last few weeks to access our Zoho data, however since last Friday, the exact same login function I had created no longer works. Have tried deciphering the error message but am not having any luck.
Running the following code I get errors:
- from zoho_functions import *
- # To create an authentication key go to the following website:
- # https://accounts.zoho.com/developerconsole
- # click on triple dots, and then self-client
- # paste the following scope:
- # aaaserver.profile.READ, ZohoCRM.settings.ALL
- # Copy the produced grant token below
- grant_token = '1000.0e3cdf67866d18ac47ccb7ec1b703e35.b668f170a7d0df79880ae485bc156f16'
- # login and fetch records
- login(grant_token)
- account_recs, account_dict, contact_recs, contact_dict, campaign_recs, campaign_dict = get_records()
with the following functions defined:
- from zcrmsdk import *
- import requests
- def login(grant_token):
- # Initialise client to access zoho
- RestClient.ZCRMRestClient.initialize()
- oauth_client = ZohoOAuth.get_client_instance()
- # post request to get refresh token
- r = requests.post('https://accounts.zoho.com/oauth/v2/token?code=' + grant_token +
- '&redirect_uri=http://portals.keanewzealand.com/callback' +
- '&client_id=1000.9GEQWUN9B0IJ626761SIOWD1E82O1S' +
- '&client_secret=7f1fed7b07deedad127817ee14793eda2d76fee6af' +
- '&grant_type=authorization_code')
- try:
- refresh_token = eval(r.content)["refresh_token"]
- user_identifier = "levon"
- oauth_client.generate_access_token_from_refresh_token(refresh_token, user_identifier)
- except Exception as e:
- print(r.content, e)
- def get_records(get_accounts=True, get_contacts=True, get_campaigns=True):
- # Pull account records from zoho
- return_list = []
- if get_accounts:
- accounts = ZCRMModule('Accounts')
- records = accounts.get_records
- #
- current_batch = 200
- page = 1
- account_recs = []
- # Run through each page of responses
- while current_batch > 199:
- data = records(page=page).data
- current_batch = len(data)
- account_recs = account_recs + data
- page = page + 1
- print(page)
- print(str(len(account_recs)) + ' Accounts Loaded')
- return_list.append(account_recs)
- # Create a dictionary linking each account id to the account object
- account_dict = {}
- for acc in account_recs:
- account_dict[acc.entity_id] = acc
- return_list.append(account_dict)
- if get_contacts:
- # Pull contact records from zoho
- contacts = ZCRMModule('Contacts')
- records = contacts.get_records
- current_batch = 200
- page = 1
- contact_recs = []
- # Run through each page of responses
- while current_batch > 199:
- data = records(page=page).data
- current_batch = len(data)
- contact_recs = contact_recs + data
- page = page + 1
- print(page)
- print(str(len(contact_recs)) + ' Contacts Loaded')
- return_list.append(contact_recs)
- # Create a dictionary linking each contact id to the contact object
- contact_dict = {}
- for con in contact_recs:
- contact_dict[con.entity_id] = con
- return_list.append(contact_dict)
- if get_campaigns:
- # Pull campaign records from zoho
- campaigns = ZCRMModule('Campaigns')
- records = campaigns.get_records
- current_batch = 200
- page = 1
- campaign_recs = []
- # Run through each page of responses
- while current_batch > 199:
- data = records(page=page).data
- current_batch = len(data)
- campaign_recs = campaign_recs + data
- page = page + 1
- print(page)
- print(str(len(campaign_recs)) + ' Campaigns Loaded')
- return_list.append(campaign_recs)
- # Create a dictionary linking each campaign id to the campaign object
- campaign_dict = {}
- for camp in campaign_recs:
- campaign_dict[camp.entity_id] = camp
- return_list.append(campaign_dict)
- return return_list
When running this, I get errors detailed in the attached log files