'Insufficient privileges' on plone python script
Asked Answered
D

3

5

I have this python script designed to rebuild the catalog for a particular content type, however when I visit it's url in the browser I get 'insufficient privileges' even when logged in as admin. 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)
Dhiman answered 22/3, 2015 at 23:50 Comment(1)
Can you get the full traceback of the error? Go to error_log in ZMI, enable logging of Unauthorized errors, then the traceback should be recorded in the error_log.Volkman
T
6

You don't need plone.api for this. Thus remove plone.api import and do:

catalog = context.portal_catalog

Toby answered 23/3, 2015 at 6:12 Comment(0)
H
3

ScriptPython is restricted Python, that means that you can not import every Python module you want. That could the reason that you can't use plone.api in ScriptPython. But you can import getToolByName in that Script and get tools like the portal_catalog with it.

from Products.CMFCore.utils import getToolByName
catalog = getToolByName('portal_catalog')
Hasidism answered 23/3, 2015 at 12:50 Comment(0)
D
1

If create your script in filesystem, you ca run.

bin/instace run your_script 

But in your case, you don't need import plone.api

Plone in ZMI have many restrictions for import something.

See more informations about portal_catalog in official plone site Documentation Query

Dubrovnik answered 14/7, 2016 at 0:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.