Python - ValueError: dictionary update sequence element #0 has length 15; 2 is required

Python - ValueError: dictionary update sequence element #0 has length 15; 2 is required

我正在使用 Zeep 尝试与 SellerCloud 上的 SOAP 客户端进行交互。当我为 API 的操作之一传递参数时,我遇到了 ValueError -

ValueError: dictionary update sequence element #0 has length 15; 2 is required

相关代码如下:

from zeep import Client
import datetime

wsdl_url = "http://tt.ws.sellercloud.com/scservice.asmx?WSDL"
client = Client(wsdl_url)
auth_type = client.get_type("ns0:AuthHeader")
sc_auth = auth_type(UserName=<username>, Password=<password>)

from_date = datetime.date(2018, 7, 3).strftime("%Y-%m-%d %H:%M:%S")
to_date = datetime.date(2018, 7, 11).strftime("%Y-%m-%d %H:%M:%S")

sc_keys = ["DateFrom", "DateTo", "UseSP", "ShippingStatusKind", "IncludeDS"]
sc_values = [from_date, to_date, "GET", "1", "TRUE"]

filters_type = client.get_type("ns0:SerializableDictionaryOfStringString")
filters = filters_type(sc_keys, sc_values)

print filters
print 'length of filters - ', len(filters)

with client.settings(extra_http_headers=sc_auth, force_https=False):
  order_ids = client.service.Orders_Get(filters)

以及堆栈跟踪错误 -

Traceback (most recent call last):
  File "seller-cloud.py", line 24, in <module>
    order_ids = client.service.Orders_Get(filters)
  File "/home/user/Envs/seller-cloud/local/lib/python2.7/site-packages/zeep/proxy.py", line 42, in __call__
    self._op_name, args, kwargs)
  File "/home/user/Envs/seller-cloud/local/lib/python2.7/site-packages/zeep/wsdl/bindings/soap.py", line 121, in send
    options=options)
  File "/home/user/Envs/seller-cloud/local/lib/python2.7/site-packages/zeep/wsdl/bindings/soap.py", line 99, in _create
    http_headers.update(client.settings.extra_http_headers)
ValueError: dictionary update sequence element #0 has length 15; 2 is required

以及在错误发生之前我的打印语句的输出 -

{
    'Keys': [
        'DateFrom',
        'DateTo',
        'UseSP',
        'ShippingStatusKind',
        'IncludeDS'
    ],
    'Values': [
        '2018-07-03 00:00:00',
        '2018-07-11 00:00:00',
        'GET',
        '1',
        'TRUE'
    ]
}
length of filters -  2

我已经为此苦苦思索了一段时间,但似乎无法找到整个 15 笔交易的发生地点。即使我传入一个空数组,如:filters = filters_type([]),我仍然得到长度为 15 的错误。

根据回溯,在此处更新 HTTP headers 时失败:

http_headers.update(client.settings.extra_http_headers)

我会调查 extra_http_headers=sc_auth 是否设置正确 headers。看起来您需要向那里传递纯 HTTP headers(字典)并且您正在为其提供一些 SOAP 结构。