I'm trying to move our sites from Zope 2.5.1 to Zope 2.8.1-final and I'm receiving an error with this script: http://www.zope.org/Members/johntynan/feedparser/ In particular, I receive the following error, when using the attached page template "nprnews.pt": "Unauthorized: You are not allowed to access 'a particular list' in this context" (see traceback.txt attached). This page template renders an rss feed that has been transformed into a dictionary (see "dictionary.txt" attached) via a python script ("feedscript") which calls an external method ("newsfeed") which uses Mark Pilgrim's feed parser to parse the xml into a python data type. If I run the python script or the external method directly (via the "test" tab in the ZMI) I have no problem viewing all the properties of the rss feed. However, if I use the page template, I still receive this error. I've tried to get around this by running the python script using a proxy role of manager or owner, but I still receive the same error. Any suggestions you might have are appreciated. John Tynan - webmaster KJZZ.org / KBAQ.org 480.774.8462
kjzz.webmaster@riomail.maricopa.edu wrote at 2006-7-24 11:13 -0700:
I'm trying to move our sites from Zope 2.5.1 to Zope 2.8.1-final and I'm receiving an error with this script:
http://www.zope.org/Members/johntynan/feedparser/
In particular, I receive the following error, when using the attached page template "nprnews.pt":
"Unauthorized: You are not allowed to access 'a particular list' in this context" (see traceback.txt attached).
This page template renders an rss feed that has been transformed into a dictionary (see "dictionary.txt" attached) via a python script ("feedscript") which calls an external method ("newsfeed") which uses Mark Pilgrim's feed parser to parse the xml into a python data type.
The object might look like a dictionary but it probably is not. Ensure that your "ExternalMethod" really returns a dict (or other simple data structure). -- Dieter
Dieter, Appreciate your help. I found a way to test if the "ExternalMethod" really returned a dict here: http://infrae.com/mailman_/pipermail/silva-dev/2004q2/001091.html And you were right! This is not seen as as a valid dictionary (nor is it seen as a string): stuff = container.externalmethod(feedurl=feedurl) test = same_type(stuff, {}) print test return printed returns "0" However, interestingly enough, if I copy and paste the all the text that is returned by the external method into the script, I am able to confirm that it is a dictionary: stuff= {'lastbuilddate': u'Mon, 24 Jul 2006 12:06:18 EDT', u'subtitle': 'U.S.', u'generator': 'NPR/RSS Generator 2.0 etc...'} test = same_type(stuff, {}) print test return printed returns "1" Also, I tried to render the copied text from the external method using the page template, and received a different error message: "TypeError: string indices must be integers" (see the attached traceback). I don't know if this last test will be useful, but I thought I'd give it a try. Do you know if there is a way of changing the data type of an object? Do you know if there is a listing of data types that I could test for? Thanks kindly, John T.
<snip> I found a way to test if the "ExternalMethod" really returned a dict here: http://infrae.com/mailman_/pipermail/silva-dev/2004q2/001091.html And you were right! This is not seen as as a valid dictionary (nor is it seen as a string): stuff = container.externalmethod(feedurl=feedurl) test = same_type(stuff, {}) print test return printed returns "0" However, interestingly enough, if I copy and paste the all the text that is returned by the external method into the script, I am able to confirm that it is a dictionary: stuff= {'lastbuilddate': u'Mon, 24 Jul 2006 12:06:18 EDT', u'subtitle': 'U.S.', u'generator': 'NPR/RSS Generator 2.0 etc...'} test = same_type(stuff, {}) print test return printed returns "1" Also, I tried to render the copied text from the external method using the page template, and received a different error message: "TypeError: string indices must be integers" (see the attached traceback). I don't know if this last test will be useful, but I thought I'd give it a try. Do you know if there is a way of changing the data type of an object? Do you know if there is a listing of data types that I could test for? </snip> There is an easy, but potentially dangerous way to turn a string representative of a python dictionary back into a 'real' python dictionary... only do this if you are sure of the contents of the dictionary: in an external method: def string2dict(instr): dict = {} dict['__builtins__'] = None return eval(instr, dict) hth Jonathan Thanks kindly, John T. --------------------------------------------------------------------------------
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
At Wednesday 26/7/2006 18:57, KJZZ Webmaster wrote:
And you were right! This is not seen as as a valid dictionary (nor is it seen as a string):
stuff = container.externalmethod(feedurl=feedurl) test = same_type(stuff, {}) print test return printed
returns "0"
However, interestingly enough, if I copy and paste the all the text that is returned by the external method into the script, I am able to confirm that it is a dictionary:
stuff= {'lastbuilddate': u'Mon, 24 Jul 2006 12:06:18 EDT', u'subtitle': 'U.S.', u'generator': 'NPR/RSS Generator 2.0 etc...'}
In this case you are using the Python syntax to create a dictionary, so it's not a surprise when it *is* a dictionary... Are you sure that your external method returns this *text*? It seems that you are looking at the string representation of some dictionary-like object. You can convert any dictionary-like object into a true dictionary using the builtin function dict: d = dict(an_object_that_acts_like_a_dictionary) Gabriel Genellina Softlab SRL __________________________________________________ Pregunt�. Respond�. Descubr�. Todo lo que quer�as saber, y lo que ni imaginabas, est� en Yahoo! Respuestas (Beta). �Probalo ya! http://www.yahoo.com.ar/respuestas
participants (5)
-
Dieter Maurer -
Gabriel Genellina -
Jonathan -
KJZZ Webmaster -
kjzz.webmaster@riomail.maricopa.edu