[Zope] Accessing httplib from a Zope Python script

Sean Winstead seanw@surehand.com
Thu, 27 Mar 2003 08:50:53 -0700


Hi,

I'm a Zope newbie who's more familiar with C# than Python. I've
encountered an obstacle and am unable to find what's wrong with my
approach. In order to solve the problem, I have searched this group's
archive as well as other resources on the web. Some posts earlier this
month were related to the problem but didn't address it exactly.

I'm trying to implement support for PayPal Instant Payment Notification
(IPN). IPN sends a POST to a URL on our Zope server. I decided to
implement a Python script to handle the POST. The first task of the
script is to send a POST back to PayPal in order to verify the
transaction originated from PayPal.

To do that, I learned that I could use the features in the httplib
module. However, if I have a crappy test script like the following:

  import httplib
  result = httplib.HTTP("http://www.paypal.com/cgi-bin/webscr")
  return result

Then I receive the following error when posting to the page:

  Error Type: Unauthorized
  Error Value: You are not allowed to access HTTP in this context

In my search for help, I learned that Zope allows Script objects to
access a subset of the Python modules, so I assumed that was the reason
for the error. In my search for help, I happened upon some articles
about using External methods to access modules. So I put the "result =
httplib..." line into function verifyPayPal, module ipnSupport.py within
the Zope\Extensions subfolder. I then added the extension to the same
folder containing the Python script. The extension has ID ipnSupport,
referening the specified script and function. When I run the following
script...

  result = verifyPayPal
  return result

The following error is returned:

  Error Type: NameError
  Error Value: global name 'verifyPayPal' is not defined

The same error occurs if I call ipnSupport instead of verifyPayPal. If I
try to import module ipnSupport then the following error is returned:

  Error Type: ImportError
  Error Value: import of "ipnSupport" is unauthorized

So I guess my questions are:

1. Why can I not import httplib into a Zope Python script object?

2. Is an external method only callable from a DTML object? If it can be
called from a script object, how do I do that?

Thanks for any help or clues you can provide.

--
Sean Winstead