繁体   English   中英

简单的xmlrpc python脚本中的属性错误

[英]Attribute error in a simple xmlrpc python script

我有一个简单的xmlrpc服务器设置来启动SMTP服务器,代码在这里:

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()

我启动此服务器,并在客户端执行以下步骤:

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

这导致以下我不明白的错误:

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

元组对象在这里是什么意思? 为什么代码要求找到属性? 有什么想法可以帮助我使此代码正常工作,即,我能够发出xmlrpc请求以初始化(并在以后使用)xmlrpc服务器内部的smtp服务器吗?

谢谢亚历克斯

smtplib文档中 ,说明了SMTP类的签名接受host和port的两个不同参数。

因此,您应该以这种方式定义send函数:

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

SMTP构造函数可能希望将字符串作为主机,并使用find方法。 但是,如果您传入元组(host, port) ,则会生成AttributeError

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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