Logger does on work in RestrictedPython script in Plone

我的未来我决定 提交于 2019-12-11 00:08:39

问题


How to print in a .cpy file (python) ? I'm using Zope/Plone and I've just started with Python. I've tried this

import logging

logger = logging.getLogger()
logger.info("hello plone")

But it doesn't work.

Thank you for your answer


回答1:


The answer above means that you cannot import any modules in RestrictedPython scripts which are through-the-web editable Plone scripts. These scripts have end-user permissions, so they are not allowed to run arbitrary Python code.

http://collective-docs.readthedocs.org/en/latest/security/sandboxing.html

You can use context.plone_log("mystring") style logging in restricted python scripts for logging purposes.




回答2:


"It doesnt' work" is awfully vague, but your problem is probably a violation of the security sandbox imposed on Python used in scripts that may be edited through the web. "Restricted Python" limits your imports to modules that have been audited to assure that they don't have nasty side effects -- like dumping noise into logs. See http://wiki.zope.org/zope2/PythonScripts for details on Restricted Python.

The general solution to this kind of problem is to build your functionality in unrestricted Python in a Python package. A Zope named utility is the usual mechanism for providing this kind of functionality, and you'll be able to reach the utility's operations from restricted Python by traversing to the named utility.



来源:https://stackoverflow.com/questions/11563865/logger-does-on-work-in-restrictedpython-script-in-plone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!