Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Insufficient privileges' on plone python script

Tags:

plone

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)
like image 677
Adrian Garner Avatar asked Mar 22 '15 23:03

Adrian Garner


3 Answers

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

catalog = context.portal_catalog

like image 129
avoinea Avatar answered Nov 27 '22 13:11

avoinea


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')
like image 34
MrTango Avatar answered Nov 27 '22 14:11

MrTango


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

like image 36
Juliano Araújo Avatar answered Nov 27 '22 15:11

Juliano Araújo