[英]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.