0
我完全失去了應該是一件容易的事情。我試圖用Python與SUDS來抓取一個WSDL URL,創建客戶端對象,修改一些信息,然後張貼備份WSDL(或任何它告訴我發佈它)。SUDS client.service。問題
我收到以下錯誤信息:
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 = '[email protected]'
From.valid = 'TRUE'
Email = client.factory.create('email')
Email.recipients = '[email protected]'
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