python login no longer working

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:
  1. from zoho_functions import *
  2. # To create an authentication key go to the following website:
  3. # https://accounts.zoho.com/developerconsole
  4. # click on triple dots, and then self-client
  5. # paste the following scope:
  6. # aaaserver.profile.READ, ZohoCRM.settings.ALL
  7. # Copy the produced grant token below
  8. grant_token = '1000.0e3cdf67866d18ac47ccb7ec1b703e35.b668f170a7d0df79880ae485bc156f16'


  9. # login and fetch records
  10. login(grant_token)
  11. account_recs, account_dict, contact_recs, contact_dict, campaign_recs, campaign_dict = get_records()
with the following functions defined:
  1. from zcrmsdk import *
  2. import requests
  3. def login(grant_token):
  4. # Initialise client to access zoho
  5. RestClient.ZCRMRestClient.initialize()
  6. oauth_client = ZohoOAuth.get_client_instance()

  7. # post request to get refresh token
  8. r = requests.post('https://accounts.zoho.com/oauth/v2/token?code=' + grant_token +
  9. '&redirect_uri=http://portals.keanewzealand.com/callback' +
  10. '&client_id=1000.9GEQWUN9B0IJ626761SIOWD1E82O1S' +
  11. '&client_secret=7f1fed7b07deedad127817ee14793eda2d76fee6af' +
  12. '&grant_type=authorization_code')
  13. try:
  14. refresh_token = eval(r.content)["refresh_token"]
  15. user_identifier = "levon"
  16. oauth_client.generate_access_token_from_refresh_token(refresh_token, user_identifier)
  17. except Exception as e:
  18. print(r.content, e)
  19. def get_records(get_accounts=True, get_contacts=True, get_campaigns=True):
  20. # Pull account records from zoho
  21. return_list = []
  22. if get_accounts:
  23. accounts = ZCRMModule('Accounts')
  24. records = accounts.get_records
  25. #
  26. current_batch = 200
  27. page = 1
  28. account_recs = []

  29. # Run through each page of responses
  30. while current_batch > 199:
  31. data = records(page=page).data
  32. current_batch = len(data)
  33. account_recs = account_recs + data
  34. page = page + 1
  35. print(page)
  36. print(str(len(account_recs)) + ' Accounts Loaded')
  37. return_list.append(account_recs)

  38. # Create a dictionary linking each account id to the account object
  39. account_dict = {}
  40. for acc in account_recs:
  41. account_dict[acc.entity_id] = acc
  42. return_list.append(account_dict)
  43. if get_contacts:
  44. # Pull contact records from zoho
  45. contacts = ZCRMModule('Contacts')
  46. records = contacts.get_records

  47. current_batch = 200
  48. page = 1
  49. contact_recs = []

  50. # Run through each page of responses
  51. while current_batch > 199:
  52. data = records(page=page).data
  53. current_batch = len(data)
  54. contact_recs = contact_recs + data
  55. page = page + 1
  56. print(page)
  57. print(str(len(contact_recs)) + ' Contacts Loaded')
  58. return_list.append(contact_recs)

  59. # Create a dictionary linking each contact id to the contact object
  60. contact_dict = {}
  61. for con in contact_recs:
  62. contact_dict[con.entity_id] = con
  63. return_list.append(contact_dict)
  64. if get_campaigns:
  65. # Pull campaign records from zoho
  66. campaigns = ZCRMModule('Campaigns')
  67. records = campaigns.get_records

  68. current_batch = 200
  69. page = 1
  70. campaign_recs = []
  71. # Run through each page of responses
  72. while current_batch > 199:
  73. data = records(page=page).data
  74. current_batch = len(data)
  75. campaign_recs = campaign_recs + data
  76. page = page + 1
  77. print(page)
  78. print(str(len(campaign_recs)) + ' Campaigns Loaded')
  79. return_list.append(campaign_recs)

  80. # Create a dictionary linking each campaign id to the campaign object
  81. campaign_dict = {}
  82. for camp in campaign_recs:
  83. campaign_dict[camp.entity_id] = camp
  84. return_list.append(campaign_dict)
  85. return return_list
When running this, I get errors detailed in the attached log files