Hi all, I'm trying to get this to work **from a XXX PythonMethod** (ie the ones that allow you to import things and are coloured red and orange!) PythonMethod do_par import xmlrpclib server_url="http://xmlrpc.server:9999" server=xmlrpclib.Server(server_url) server.getTranscript(number) I call it with a dtml doc <form action="do_par" method=post> <input type=text name="number:int"> </form> The PythonMethod returns a blank page (whether from the form or the 'try' tab) If I make the PythonMethod be; import xmlrpclib def doit(number): server_url="http://xmlrpc.server:9999" server=xmlrpclib.Server(server_url) return server.getTranscript(number) doit(number) Then I get this error, when called from either the form or the 'try' tab. <!-- Error type: NameError Error value: xmlrpclib --> <!-- Traceback (innermost last): File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, line 214, in publish_module File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, line 179, in publish File /home/nnle/MEDFAC_SERVER/lib/python/Zope/__init__.py, line 202, in zpublisher_exception_hook (Object: ElementWithAttributes) File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, line 165, in publish File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: do_par) File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, line 102, in call_object (Object: do_par) File /home/nnle/MEDFAC_SERVER/lib/python/Products/PythonMethod/PythonMethod .py, line 168, in __call__ (Object: do_par) (Info: (('961160610',), {}, None)) File <string>, line 9, in do_par File <string>, line 6, in doit NameError: (see above) --> I'd like to work from PythonMethods as they offer the promise of speedy editing, so what am I doing wrong this time? :( getTranscript does work, because all this code works from the Python interpreter. ta tone. ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
Tone, Is the page 'really' blank, have a look at the source. It maybe that the Python Method is returning a reference to an object, which would look something like <blah blah blah> Which of course wouldn't get rendered by the browser. HTH Phil phil.harris@zope.co.uk | -----Original Message----- | From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Tony | McDonald | Sent: Friday, February 11, 2000 1:40 PM | To: Zope List | Subject: [Zope] XML-RPC woes | | | Hi all, | I'm trying to get this to work **from a XXX PythonMethod** (ie the | ones that allow you to import things and are coloured red and orange!) | | PythonMethod do_par | | import xmlrpclib | | server_url="http://xmlrpc.server:9999" | server=xmlrpclib.Server(server_url) | server.getTranscript(number) | | I call it with a dtml doc | | <form action="do_par" method=post> | <input type=text name="number:int"> | </form> | | The PythonMethod returns a blank page (whether from the form or | the 'try' tab) | | If I make the PythonMethod be; | import xmlrpclib | | def doit(number): | server_url="http://xmlrpc.server:9999" | server=xmlrpclib.Server(server_url) | return server.getTranscript(number) | | doit(number) | | Then I get this error, when called from either the form or the 'try' tab. | <!-- | Error type: NameError | Error value: xmlrpclib | --> | <!-- | Traceback (innermost last): | File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, | line 214, in publish_module | File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, | line 179, in publish | File /home/nnle/MEDFAC_SERVER/lib/python/Zope/__init__.py, line | 202, in zpublisher_exception_hook | (Object: ElementWithAttributes) | File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, | line 165, in publish | File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/mapply.py, line | 160, in mapply | (Object: do_par) | File /home/nnle/MEDFAC_SERVER/lib/python/ZPublisher/Publish.py, | line 102, in call_object | (Object: do_par) | File | /home/nnle/MEDFAC_SERVER/lib/python/Products/PythonMethod/PythonMethod | .py, line 168, in __call__ | (Object: do_par) | (Info: (('961160610',), {}, None)) | File <string>, line 9, in do_par | File <string>, line 6, in doit | NameError: (see above) | | --> | | I'd like to work from PythonMethods as they offer the promise of | speedy editing, so what am I doing wrong this time? :( | | getTranscript does work, because all this code works from the Python | interpreter. | | ta | tone. | ------ | Dr Tony McDonald, FMCC, Networked Learning Environments Project | http://nle.ncl.ac.uk/ | The Medical School, Newcastle University Tel: +44 191 222 5888 | Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2 | | _______________________________________________ | Zope maillist - Zope@zope.org | http://lists.zope.org/mailman/listinfo/zope | ** No cross posts or HTML encoding! ** | (Related lists - | http://lists.zope.org/mailman/listinfo/zope-announce | http://lists.zope.org/mailman/listinfo/zope-dev ) |
At 2:44 pm +0000 11/2/00, Phil Harris wrote:
Tone,
Is the page 'really' blank, have a look at the source.
It maybe that the Python Method is returning a reference to an object, which would look something like
<blah blah blah>
Which of course wouldn't get rendered by the browser.
HTH
Phil
Cheers Phil, However "on closer examination" of the Zope-Dev list! :) I found a clue, I should use this construct; <params>number</params> def doit(number): import xmlrpclib server_url="http://xmlrpc.server:9999" server=xmlrpclib.Server(server_url) return server.getTranscript(number) print doit(number) return printed I couldn't find 'printed' in any file in the PythonMethods docs or .py files, but it was in the 'Voodoo area' (ie the zbytecodehacks directory...deep deep python). Getting there! Cheers tone. ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
----- Original Message ----- From: Tony McDonald <tony.mcdonald@ncl.ac.uk>
server_url="http://xmlrpc.server:9999" server=xmlrpclib.Server(server_url) server.getTranscript(number)
Is this the whole text? You never return anything, so the caller gets 'None' back. (Don't worry, I've done that myself a few times)
If I make the PythonMethod be; import xmlrpclib
def doit(number): server_url="http://xmlrpc.server:9999" server=xmlrpclib.Server(server_url) return server.getTranscript(number)
doit(number)
You can't treat PythonMethods like modules. In a module, the 'import' would put 'xmlrpclib' into the module-global namespace, where 'doit' could find it. In this PM, 'import' creates a local variable which is not visible from 'doit'. Unless it really helps reduce redundancy, functions in PMs aren't generally a good idea. You could make this example work by adding a 'global xmlrpclib' line before the 'import' line, though. Cheers, Evan @ digicool
At 9:35 am -0600 11/2/00, Evan Simpson wrote:
You can't treat PythonMethods like modules. In a module, the 'import' would put 'xmlrpclib' into the module-global namespace, where 'doit' could find it. In this PM, 'import' creates a local variable which is not visible from 'doit'. Unless it really helps reduce redundancy, functions in PMs aren't generally a good idea. You could make this example work by adding a 'global xmlrpclib' line before the 'import' line, though.
Cheers,
Evan @ digicool
Thanks for the info. Evan, I eventually got it to work by doing this; global xmlrpclib import xmlrpclib server_url="http://xmlrpc.server:9999" server=xmlrpclib.Server(server_url) print server.getValidMethods() return printed point taken about functions etc. many thanks, now to start doing some XML-RPC work.... :) tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
participants (3)
-
Evan Simpson -
Phil Harris -
Tony McDonald