"Not enough privileges" on plone python script

I have this python script designed to restore a directory for a certain type of content, however, when I find its url in the browser, I get "insufficient privileges" even when logged in as an administrator. How can I run something like this?

import plone.api

catalog = plone.api.portal.get_tool(name='portal_catalog') for brain in catalog(portal_type='Resource'):
    obj = brain.getObject()
    catalog.catalog_object(obj)
+4
source share
3 answers

You do not need plone.api for this . Thus remove the plone.api import and do:

catalog = context.portal_catalog

+6
source

ScriptPython Python, , Python, . , plone.api ScriptPython. getToolByName Script , portal_catalog.

from Products.CMFCore.utils import getToolByName
catalog = getToolByName('portal_catalog')
+3

If you create your script on the file system, you will run.

bin/instace run your_script 

But in your case you do not need import plone.api

Plone in ZMI has many import restrictions.

Additional information about the portal_catalog on the official plone website Request documentation

+1
source

All Articles