I'm haing some problems calling manage_addPythonScript. While the manual mentions it's existence I can find no examples of how to call it (a common complaint!). However, when I get something that runs I get Error Type: TypeError Error Value: 'in' or 'not in' needs sequence right argument (which I have only ever seen where python versions are wrong.....) Is this a permisssions problem, a bug, or simply user error? I'd appreciate your wisdom....... Charles My code: # Example code: from Products.PythonScripts.PythonScript import PythonScript # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE def addPythonScript(obj,id): manage_addPythonScript(obj,id) try: j=context.objectIds('Script (Python)') k=j.index('getTableDetailsStatic') print 'Found',k print context.objectValues('Script (Python)')[k].absolute_url(relative=None) print context.absolute_url(relative=None) if context.objectValues('Script (Python)')[k].absolute_url(relative=None) == \ context.absolute_url(relative=None)+"/getTableDetailsStatic": print 'Defined' else: print 'Undefined' a=context.manage_addPythonScript('getTableDetailsStatic',REQUEST=None) except: print 'Not Found' addPythonScript(context,'getTableDetailsStatic') return printed System: Zope Version (Zope 2.5.1 (binary release, python 2.1, linux2-x86), python 2.1.3, linux2) Python Version 2.1.3 (#1, Apr 15 2002, 11:13:45) [GCC 2.7.2.3] System Platform linux2 SOFTWARE_HOME /home/usr/local/src/Zope/lib/python INSTANCE_HOME /home/usr/local/src/Zope CLIENT_HOME /home/usr/local/src/Zope/var Process Id 1998 (4101) Running For 43 days 12 hours 15 min 55 sec Traceback: <!-- Traceback (innermost last): File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 150, in publish_module File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 114, in publish File /home/usr/local/src/Zope/lib/python/Zope/__init__.py, line 159, in zpublisher_exception_hook (Object: Administration) File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 98, in publish File /home/usr/local/src/Zope/lib/python/ZPublisher/mapply.py, line 88, in mapply (Object: test) File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 39, in call_object (Object: test) File /home/usr/local/src/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 252, in __call__ (Object: test) File /home/usr/local/src/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 283, in _bindAndExec (Object: test) File /home/usr/local/src/Zope/lib/python/Products/PythonScripts/PythonScript.py, line 302, in _exec (Object: test) (Info: ({'script': <PythonScript instance at 8ff9208>, 'context': <Folder instance at 8f0af98>, 'container': <Folder instance at 8deab20>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 2, in test File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeGuards.py, line 144, in guarded_import File /home/usr/local/src/Zope/lib/python/AccessControl/SecurityManager.py, line 83, in validate File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeSecurityPolicy.py, line 157, in validate TypeError: (see above) <!-- Traceback (innermost last): File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 150, in publish_module File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 114, in publish File /home/usr/local/src/Zope/lib/python/Zope/__init__.py, line 159, in zpublisher_exception_hook (Object: Administration) File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 98, in publish File /home/usr/local/src/Zope/lib/python/ZPublisher/mapply.py, line 88, in mapply (Object: test) File /home/usr/local/src/Zope/lib/python/ZPublisher/Publish.py, line 39, in call_object (Object: test) File /home/usr/local/src/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 252, in __call__ (Object: test) File /home/usr/local/src/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 283, in _bindAndExec (Object: test) File /home/usr/local/src/Zope/lib/python/Products/PythonScripts/PythonScript.py, line 302, in _exec (Object: test) (Info: ({'script': <PythonScript instance at 8ff9208>, 'context': <Folder instance at 8f0af98>, 'container': <Folder instance at 8deab20>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 2, in test File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeGuards.py, line 144, in guarded_import File /home/usr/local/src/Zope/lib/python/AccessControl/SecurityManager.py, line 83, in validate File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeSecurityPolicy.py, line 157, in validate TypeError: (see above)
Charles Zealey wrote at 2003-5-15 14:39 +0100:
I'm haing some problems calling manage_addPythonScript. While the manual mentions it's existence I can find no examples of how to call it (a common complaint!).
However, when I get something that runs I get
Error Type: TypeError Error Value: 'in' or 'not in' needs sequence right argument
(which I have only ever seen where python versions are wrong.....)
Is this a permisssions problem, a bug, or simply user error?
I'd appreciate your wisdom.......
The primary wisdom is to look at the traceback :-) It tells you that the problem is in line 2 of your Python Script "test".
... # Example code: from Products.PythonScripts.PythonScript import PythonScript ... File Script (Python), line 2, in test File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeGuards.py, line 144, in guarded_import File /home/usr/local/src/Zope/lib/python/AccessControl/SecurityManager.py, line 83, in validate File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeSecurityPolicy.py, line 157, in validate TypeError: (see above)
I expect that your are not allowed to import the module "PythonScript". I agree however that this error message gives you little chance to see this. Please file a bug report to <http://collector.zope.org/Zope>. The standard method to create a PythonScript (in an ObjectManager "om") is: om.manage_addProduct['PythonScripts'].manage_addPythonScript(id) myPythonScript= getattr(om,id) You can later use the PythonScript method "ZPythonScript_edit" to set parameters and body of the script. Dieter
Dieter Thank you. I think I was 90% there but that's failure! Can you tell me if my failure to access PythonScript due to file permissions, role security attributes, or Zope paranoia (need to use external method??)? It certainly does not fail cleanly and I have raised the bug. Charles ----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Charles Zealey" <charles@itsolve.co.uk> Cc: <zope@zope.org> Sent: Thursday, May 15, 2003 8:09 PM Subject: Re: [Zope] manage_addPythonScript
Charles Zealey wrote at 2003-5-15 14:39 +0100:
I'm haing some problems calling manage_addPythonScript. While the manual mentions it's existence I can find no examples of how to call it (a common complaint!).
However, when I get something that runs I get
Error Type: TypeError Error Value: 'in' or 'not in' needs sequence right argument
(which I have only ever seen where python versions are wrong.....)
Is this a permisssions problem, a bug, or simply user error?
I'd appreciate your wisdom.......
The primary wisdom is to look at the traceback :-)
It tells you that the problem is in line 2 of your Python Script "test".
... # Example code: from Products.PythonScripts.PythonScript import PythonScript ... File Script (Python), line 2, in test File /home/usr/local/src/Zope/lib/python/AccessControl/ZopeGuards.py, line 144, in guarded_import File /home/usr/local/src/Zope/lib/python/AccessControl/SecurityManager.py, line 83, in validate File
/home/usr/local/src/Zope/lib/python/AccessControl/ZopeSecurityPolicy.py, line
157, in validate TypeError: (see above)
I expect that your are not allowed to import the module "PythonScript".
I agree however that this error message gives you little chance to see this.
Please file a bug report to <http://collector.zope.org/Zope>.
The standard method to create a PythonScript (in an ObjectManager "om") is:
om.manage_addProduct['PythonScripts'].manage_addPythonScript(id) myPythonScript= getattr(om,id)
You can later use the PythonScript method "ZPythonScript_edit" to set parameters and body of the script.
Dieter
Charles Zealey wrote at 2003-5-15 23:45 +0100:
Thank you. I think I was 90% there but that's failure! Can you tell me if my failure to access PythonScript due to file permissions, role security attributes, or Zope paranoia (need to use external method??)?
Most Python modules are dangerous (when exposed to the Web). They must not be imported by untrusted code. Beginning with Zope 2.2, Zope.com changed policy. Formerly, everything not explicitly forbidden was allowed. Now, everything not explicitly allowed is forbidden. As a consequence, you have a very limited set of modules you can import. Many harmless modules are not importable because nobody took the time to proof they are indeed harmless. Reading "PythonScripts/README.txt", you can find out, how you can declare for your Zope installation that you are sure that a module is harmless and can be imported.
It certainly does not fail cleanly and I have raised the bug.
Fine. Dieter
participants (2)
-
Charles Zealey -
Dieter Maurer