简体   繁体   中英

Attribute error in a simple xmlrpc python script

I have a simple xmlrpc server setup to start a SMTP server, the code is here:

from SimpleXMLRPCServer import SimpleXMLRPCServer
import smtplib

# Create server
server = SimpleXMLRPCServer(("localhost", 1025), allow_none = True)

# add the introspection functions (system.listMethods, system.methodHelp 
# and system.methodSignature)
server.register_introspection_functions()

def send(host, port):
    server = smtplib.SMTP((host, port), None)

# register this method
server.register_function(send, 'send')

# start server
server.serve_forever()

I start this server and on the client side I perform the following steps:

import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:1025')
s.send('0.0.0.0',25)

which result in the following error I do not understand:

xmlrpclib.Fault: <Fault 1: "<type 'exceptions.AttributeError'>:'tuple' object has no attribute 'find'">

What tuple object is meant here? Why does the code require an attribute find? Any ideas that help me to get this code working, ie that I am able to make a xmlrpc request to initialize (and later use) a smtp server inside the xmlrpc server?

Thanks Alex

In the smtplib documentation it's stated the the signature of the SMTP class accepts two distinct parameters for host and port.

Thus you should define your send function in this way:

def send(host, port):
    server = smtplib.SMTP(host, port)

Probably the SMTP constructor expects a string as host, and uses the find method. But if you pass in the tuple (host, port) then that AttributeError is generated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM