我完全迷失了应该是一件容易的事。
我正在尝试将 Python 与 SUDS 一起使用来获取 WSDL URL、创建客户端对象、修改一些信息,然后发布备份 WSDL(或者它告诉我发布它的地方)。
我收到以下错误消息:
Traceback (most recent call last):
File "./test.py", line 47, in <module>
email_sent = client.service.sendEmail(From, SenderContext, Email)
NameError: name 'client' is not defined
如果我删除代码中的“尝试:”部分并插入打印代码来打印对象,一切正常。它确实获取信息并进行我想要的更改。
我不明白的是客户端对象已创建,我正在尝试将信息发布备份,但不能。任何人有任何使用 XML 和 Python 的经验吗?
import sys
import logging
import traceback as tb
import suds.metrics as metrics
import unittest
from suds import null, WebFault
from suds.client import Client
def sendTestMail():
url = 'wsdl url at my company'
client = Client(url)
SenderContext = client.factory.create('senderContext')
SenderContext.registeredSenderId = 'Endurance'
SenderContext.mailType = 'TRANSACTIONAL_OTHER'
SenderContext.subSenderId = 12345
From = client.factory.create('emailAddressBean')
From.address = 'me@somecompany.com'
From.valid = 'TRUE'
Email = client.factory.create('email')
Email.recipients = 'me@somecompany.com'
Email.ccRecipients = ''
Email.bccRecipients = ''
Email.agencyId = ''
Email.content = 'This is a test of sending'
Email.contentType = 'text/plain'
Email.description = ''
#Email.from = From
Email.fromName = 'An Employee'
Email.subject = 'This is a test'
Email.mrrId = ''
Email.templateId = ''
try:
email_sent = client.service.sendEmail(From, SenderContext, Email)
except WebFault, e:
print e
if __name__ == '__main__':
errors = 0
sendTestMail()
print '\nFinished: errors=%d' % errors