Python suds attirbuteError:Fault实例没有属性'detail'

时间:2015-06-29 15:10:35

标签: python oop suds

Howdie do,

我创建了一个包类,它设置了一些默认值,例如出货单,收货人,包裹和商品。

问题是,当我去调用suds客户端的方法shippackage时,我收到错误:

AttributeError: Fault instance has no attribute 'detail'

下面列出的第一个文件是我的测试文件,它设置了必要的词典:

import ship

# Create a new package object
package1 = ship.Package('TX')

# Set consignee
package1.setconsignee('Dubs Enterprise', 'JW', '2175 14th Street', 'Troy', 'NY', '12180', 'USA')

# Set default packaging
package1.setdefaults('CUSTOM', '12/12/15', 'oktoleave')

# Add commodity description with each package
package1.addpackage('12.3 lbs', '124.00')
package1.addcommodity('This is package number 1', '23.5 lbs')

# Add commodity list to defaults dictionary
package1.setcommoditylist()

# Add package list to packages dictionary
package1.setpackagelist()
package1.shippackage()

正在导入的模块如下:

from suds.client import Client
from suds.bindings import binding

binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
client = Client('http://localhost/ProgisticsAMP/amp.svc/wsdl', headers={'Content-Type': 'application/soap+xml'},
                faults=False)


class Package(object):

    def __init__(self, shipper):
        self.commoditylist = []
        self.commodityContents = {}
        self.consignee = {}
        self.defaults = {}
        self.packagelist = []
        self.packages = {}

        self.defaults['shipper'] = shipper

    def setconsignee(self, company, contact, address, city, state, zip, country):
        self.consignee['company'] = company
        self.consignee['contact'] = contact
        self.consignee['address1'] = address
        self.consignee['city'] = city
        self.consignee['stateProvince'] = state
        self.consignee['postalCode'] = zip
        self.consignee['countrySymbol'] = country

        self.defaults['consignee'] = self.consignee

    def setdefaults(self, packaging, shipdate, deliverymethod):
        self.defaults['packaging'] = packaging
        self.defaults['shipdate'] = shipdate
        self.defaults['deliveryMethod'] = deliverymethod

    def addcommodity(self, description, unitweight):
        commodity = {}
        commodity['description'] = description
        commodity['unitWeight'] = {'value': unitweight}

        self.commoditylist.append(commodity)

    def addpackage(self, weight, declarevalue):
        package = {}
        package['weight'] = {'value': weight}
        package['declaredValueAmount'] = {'amount': declarevalue, 'currency': 'USD'}
        self.packagelist.append(package)

    def setcommoditylist(self):
        self.commodityContents = {'item': self.commoditylist}

        self.defaults['commodityContents'] = self.commodityContents

    def setpackagelist(self):
        self.packages = {'item': self.packagelist}

    def shippackage(self):
        print self.defaults
        print self.packages

        # print client
        response = client.service.Ship('CONNECTSHIP_UPS.UPS.GND', self.defaults, self.packages, True, 'release')
        result = response.result
        print result

在shippackage方法中,我打印self.packages和self.defaults并在我打电话之前确认他们有数据

client.service.Ship()

所以我知道在调用client.service.Ship()

之前它确实有值

我在这里遗漏了什么吗?为什么不采用我设置的默认值和包字典?

1 个答案:

答案 0 :(得分:0)

问题在于'shipdate'值

WSDL期望使用不同格式的发货日期。

我能够找到这个的唯一方法是将我的端点从SOAP 1.2切换到1.1

我直接编辑web.config文件

现在100%正常工作