Select to view content in your preferred language

survey_by_id.generate_report error CONT_0004: User folder does not exist

732
2
Jump to solution
04-26-2023 08:44 AM
JamesCrandall
MVP Frequent Contributor

ArcPro 2.9.7

Conda 3.7

Error: "Exception: upload destination is invalid. CONT_0004: User folder does not exist."

 

I have a hosted AGO Notebook that works as expected and now I'm attempting to bring this down and re-write locally as a standalone .py script.  The local .py script works but fails on this line,

 

pdf_report = survey_by_id.generate_report(templates[0], where=whereClause, utc_offset=offset, output_format="pdf", report_title=reportName, merge_files="nextPage", folder_id='e1d58030cf4a40a989beffc9349fa501')

 

 

I'm getting the AGO folder id by simply navigating to it and copying the &folder= parameter value from the url (so I know it's correct and it also works in the NB when running on AGOL).

 

Reason for bringing down local is over the life of the existing NB that runs daily on AGOL, we've seen some hiccups of that implementation -- sometimes it may have been a task scheduler thing or the NB would execute without errors/issues but would not generate the pdf output for some reason or another (but on subsequent manual attempts it would work just fine).  The majority of the time it runs without issue but there's no real good way to monitor things and handle problems when they occur -- when you have a high visibility output that the NB generates then this is a problem because it requires constant babysitting.

We have a ton of experience with py 2.7 scripts running on a windows server vm that get run via the task scheduler and having them run locally there's simply more options available to handle execution failures in more hands-off approach.

0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

Resolved.  Simply removing the Folder_ID parameter from the generate_report() method automatically writes the output to the local directory C:\Users\[username]\AppData\Local\Temp\5

From there I can simply use shutil.copyfile() to put it into a desired directory.

save_pdf=r'H:\AGOL\bga\bgaReportCopy.pdf'
pdf_report = survey_by_id.generate_report(templates[0], where=whereClause, utc_offset=offset, output_format="pdf", report_title=reportName, merge_files="nextPage")
    
shutil.copyfile(pdf_report,save_pdf)

View solution in original post

2 Replies
JamesCrandall
MVP Frequent Contributor

Edit: removing the Folder_ID= parameter automatically puts the output into C:\Users\[UserName]\AppData\Local\Temp\5

Is there any way to specify this directory instead?

 

Perhaps overcomplicating this --- for the AGO NB it needed to create content in a specific AGO folder for a specific user/account.  However, I'm starting to better understand the differences running locally and perhaps there's no need to deal with created the report output and saving to a folderId.

From https://developers.arcgis.com/python/api-reference/arcgis.apps.survey123.html it mentions, 

 

To save to disk, do not specify a folder_id

 

So, removing the folder_id parameter in that generate_report() method it actually worked!  However, I'm unsure where it saved the output pdf to?  Also, I attempted to add a save_folder parameter but it doesn't recognize that as a valid input.

 

0 Kudos
JamesCrandall
MVP Frequent Contributor

Resolved.  Simply removing the Folder_ID parameter from the generate_report() method automatically writes the output to the local directory C:\Users\[username]\AppData\Local\Temp\5

From there I can simply use shutil.copyfile() to put it into a desired directory.

save_pdf=r'H:\AGOL\bga\bgaReportCopy.pdf'
pdf_report = survey_by_id.generate_report(templates[0], where=whereClause, utc_offset=offset, output_format="pdf", report_title=reportName, merge_files="nextPage")
    
shutil.copyfile(pdf_report,save_pdf)