Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'access_token' in authenticate method after updates on June 30 #62

Open
linasaltanav opened this issue Jul 2, 2021 · 9 comments

Comments

@linasaltanav
Copy link

Export Marketo list fails with
result_text += future.result()
File "/opt/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 428, in result
return self.__get_result()
File "/opt/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/opt/anaconda3/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/etl/imports/marketo/python_scripts/export_marketo_leads.py", line 42, in export_leads
filters={args.filters: list_id})
File "/home/ec2-user/.local/lib/python3.7/site-packages/marketorestpython/client.py", line 299, in execute
result = method_map[method](*args, **kargs)
File "/home/ec2-user/.local/lib/python3.7/site-packages/marketorestpython/client.py", line 5303, in create_leads_export_job
return self._create_bulk_export_job('leads', *args, **kargs)
File "/home/ec2-user/.local/lib/python3.7/site-packages/marketorestpython/client.py", line 5248, in _create_bulk_export_job
self.authenticate()
File "/home/ec2-user/.local/lib/python3.7/site-packages/marketorestpython/client.py", line 328, in authenticate
self.token = data['access_token']
KeyError: 'access_token'

@jepcastelein
Copy link
Owner

@linasaltanav it works for me. How are you creating the MarketoClient? I've tested these variations:

mc = MarketoClient(MUNCHKIN_ID, CLIENT_ID, CLIENT_SECRET)
mc = MarketoClient(munchkin_id=MUNCHKIN_ID, client_id=CLIENT_ID, client_secret=CLIENT_SECRET)

@linasaltanav
Copy link
Author

Yes, I create the same way. mc = MarketoClient(args.munchkin_id, args.client_id, client_secret).
My code works fine for more than year and started failing on June 30. It works for 40 min and fails after.

@jepcastelein
Copy link
Owner

@linasaltanav thanks for the details. It sounds like refreshing the token for long-running processes doesn't work correctly with the latest version. Please revert to the previous version 0.5.10 while I investigate this.

@jepcastelein
Copy link
Owner

I reviewed the most recent change and I don't immediately see how those changes may have caused the error you experienced. The error occurs because the authentication call to /identity/oauth/token apparently doesn't return an access_token, so you get a KeyError. Nothing changed in the authentication code. Was there maybe a one-off Marketo API issue?

Here are the changes:
0dc3369#diff-7239c0975231cb9bc09a765559bad6f1f428966db39ae6c795e6fd9d78433578
If you have an idea what could cause the issue, please let me know.

@linasaltanav
Copy link
Author

Unfortunately reverting to version 0.5.10 was not successful. It is not one-off issue. I have restarted it yesterday, same error.
If it is a short-running process, everything is fine. For a long it raises KeyError.

@jepcastelein
Copy link
Owner

@linasaltanav thanks for reporting back. Do you mean you still get the error with 0.5.10 or that - due to your setup - you cannot revert back to an older version of the library?
I will try to create a test setup that reproduces this issue

@linasaltanav
Copy link
Author

I have reverted to the previous version 0.5.10 and still have the issue. I am debugging the issue as well, let you know if I find more details on that.

@linasaltanav
Copy link
Author

I finally catch the payload in the authentication method. it returns
data {'error': 'server_error', 'error_description': 'Internal Server Error'}

@linasaltanav
Copy link
Author

Looks like it makes sense to add 'server_error' into authenticate.
data['error'] in ['unauthorized', 'invalid_client', 'server_error']:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants