Bulk Job Retrieval Error
Opened this issue · 5 comments
When trying to retrieve a bulk job file, this error is being generated:
Traceback (most recent call last): File "marketo.py", line 18, in <module> export_file_contents = mc.execute(method='get_leads_export_job_file', job_id='9e1f342e-9365-4173-8818-ec1971079f72') File "/mnt/d/code/marketo/lib/python3.8/site-packages/marketorestpython/client.py", line 273, in execute result = method_map[method](*args, **kargs) File "/mnt/d/code/marketo/lib/python3.8/site-packages/marketorestpython/client.py", line 4956, in get_leads_export_job_file return self._export_job_state_machine('leads', 'file', *args, **kargs) File "/mnt/d/code/marketo/lib/python3.8/site-packages/marketorestpython/client.py", line 4953, in _export_job_state_machine return result['result'] TypeError: 'Response' object is not subscriptable
Any Ideas?
Hi @jepcastelein , I am using version 0.5.8 and I am getting the above error as well.
I tried modifying the _export_job_state_machine method to return result
instead of return result['result']
to see what would happen and the response was a 404. Below is the printout from the unmodified version.
You can see that the create_leads_export_job
, enqueue_leads_export_job
, get_leads_export_job_status
methods are all working fine, the only thing throwing an error is the get_leads_export_job_file
method.
[{'exportId': '46a1178f-223c-4ce7-80b0-f278a5a91533', 'format': 'CSV', 'status': 'Created', 'createdAt': '2021-01-22T16:41:51Z'}]
[{'exportId': '46a1178f-223c-4ce7-80b0-f278a5a91533', 'format': 'CSV', 'status': 'Queued', 'createdAt': '2021-01-22T16:41:51Z', 'queuedAt': '2021-01-22T16:41:52Z'}]
[{'exportId': '46a1178f-223c-4ce7-80b0-f278a5a91533', 'format': 'CSV', 'status': 'Queued', 'createdAt': '2021-01-22T16:41:51Z', 'queuedAt': '2021-01-22T16:41:52Z'}]
Traceback (most recent call last):
File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/ES_Fetch_MarketoSmartList/fetch_mkto_list.py", line 33, in <module>
export_file_contents = mc.execute(method='get_leads_export_job_file', job_id=new_export_job_details[0]['exportId'])
File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/env/lib/python3.8/site-packages/marketorestpython/client.py", line 292, in execute
result = method_map[method](*args, **kargs)
File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/env/lib/python3.8/site-packages/marketorestpython/client.py", line 5179, in get_leads_export_job_file
return self._export_job_state_machine('leads', 'file', *args, **kargs)
File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/env/lib/python3.8/site-packages/marketorestpython/client.py", line 5176, in _export_job_state_machine
return result['result']
TypeError: 'Response' object is not subscriptable
@phil-epl I think the problem is that you're getting a 404 on the get_leads_export_job_file
method because the file isn't there yet, the status is still queued
. We could probably tweak the error handling for this situation, but as soon as the file is available, this method should work okay.
if state == 'file' and result.status_code == 200:
return result.content
return result['result']
So in your case the state == 'file' but the status_code is not 200.
So what do you think would be the right way of making the "get data" part of the process wait until the file is available?
new_export_job_details = mc.execute(method='create_leads_export_job',
fields=['email']
,filters={'smartListId': '10131936'})
#enqueue a job
enqueued_job_details = mc.execute(method='enqueue_leads_export_job', job_id=new_export_job_details[0]['exportId'])
#check job status
export_job_status = mc.execute(method='get_leads_export_job_status', job_id=new_export_job_details[0]['exportId'])
# get data
export_file_contents = mc.execute(method='get_leads_export_job_file', job_id=new_export_job_details[0]['exportId'])
@phil-epl yes, you need to poll the status until it says "completed" https://developers.marketo.com/rest-api/bulk-extract/bulk-lead-extract/#polling_job_status