user2808871
user2808871

Reputation: 1

SUDS client.service. issue

I am utterly lost at what should be an easy task.

I am trying to use Python with SUDS to grab a WSDL URL, create client objects, modify some information, and then post back up the WSDL (Or where ever it tell me to post it).

I get the following error message:

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

If I remove the "Try:" section in the code and insert come print code to print the objects, everything works just fine. It does grab the information and do the changes I want.

What I don't understand is that the client object is created and I am trying to post the information back up, but can't. Any one have any experience with XML and 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

Upvotes: 0

Views: 1564

Answers (1)

acelives
acelives

Reputation: 51

You define client in the sendTestMail() class, but then use a lower-level indentation in your try/except statement. Therefore, client is not within scope at this point. Either indent your try/except block to be within the sendTestMail() scope or declare client globally.

Upvotes: 1

Related Questions