[Zope] Re: Python script, urllib2

Jonathan dev101 at magma.ca
Mon Dec 18 17:03:36 EST 2006


----- Original Message ----- 
From: "Mihamina Rakotomandimby" 
<mihamina.rakotomandimby at etu.univ-orleans.fr>
To: "Jonathan" <dev101 at magma.ca>
Sent: Monday, December 18, 2006 1:34 PM
Subject: Python script, urllib2


> Hi,
> I want to fetch at least the <head></head> part of an html static page
> from a python script (added through the ZMI).
> Here is the content of the python script:
>
> import urllib2
> t="http://www.asso-polyvalente.fr/"
> req=urllib2.Request(t)
> h=urllib2.urlopen(req)
> the_page=h.read()
> print the_page
> printed
>
> Then I get a:
> "You are not allowed to access 'Request' in this context"
>
> Ok. I remember in some ML I subscribe, I could allow some action/module
> by listing the allowed actions/modules somewhere.
> Unfortunately, I cant remember where/wht to do.
> Would you help me?

I would recommend using urllib in an external method, not a python script.

If you want to use a python script to access the contents of a static page 
(static page created via the ZMI), why don't you do something like:

staticPage = 
context.restrictedTraverse('/path/to/the/static/page/staticPage.html')

The variable staticPage will then hold the contents of the static page and 
you can process it as you require.

Jonathan

ps. pls keep your posts on the list so that others can help and so that 
future generations can find/follow the thread!






More information about the Zope mailing list