Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-ValueError:字典更新序列元素#0的长度为15;2是必需的_Python_Valueerror_Zeep - Fatal编程技术网

Python-ValueError:字典更新序列元素#0的长度为15;2是必需的

Python-ValueError:字典更新序列元素#0的长度为15;2是必需的,python,valueerror,zeep,Python,Valueerror,Zeep,我正在使用Zeep尝试与SellerCloud上的SOAP客户端进行交互。当我为API的一个操作传入参数时,我遇到了ValueError- ValueError:字典更新序列元素#0的长度为15;2是必需的 以下是相关代码: from zeep import Client import datetime wsdl_url = "http://tt.ws.sellercloud.com/scservice.asmx?WSDL" client = Client(wsdl_url) auth_typ

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

ValueError:字典更新序列元素#0的长度为15;2是必需的

以下是相关代码:

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)

我在这件事上绞尽脑汁已经有一段时间了,但似乎找不到这15年的交易到底发生在哪里。即使我传入一个空数组,如:
filters=filters\u type([])
,我仍然会得到一个长度为15的错误。

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

http_headers.update(client.settings.extra_http_headers)

我将调查
extra\u http\u headers=sc\u auth
是否设置了正确的头。看起来您需要传递这些简单的HTTP头(dict),并为其提供一些SOAP结构。

我猜,从这个示例很难说,但我认为过滤器需要作为键值对的字典传递。i、 是的,我也试过了。将字典直接传递到
client.service.Orders\u Get(filters)
并绕过
filters\u type
步骤会产生相同的错误。看起来可能就是这样。但现在我遇到了一个新问题。
client.service.Orders\u-Get()
显然需要特定的SOAP结构来正确地进行身份验证,从API的文档来看,这类似于
Orders\u-Get(SCAuth、SCSettings、filters)
。很遗憾,在此处传入多个参数会引发一个错误,表示只允许一个参数。错误消息说明在方法调用中需要身份验证-
zeep.exceptions.Fault:System.Web.Services.Protocols.SoapException:服务器无法处理请求。-->系统异常:请在服务对象的AuthHeaderValue属性中提供身份验证信息。
不确定。看一下这些文档:可能您需要使用
\u soapheaders
命名参数和您拥有的身份验证信息来调用
Orders\u Get
。使用
\u soapheaders
肯定会有帮助。看起来身份验证过程现在正在正确启动。果不其然,现在我被告知我的用户名无效——尽管它被复制/粘贴。这是一个无法真正解决的问题,所以我会将您的解决方案标记为正确!谢谢
{
    '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
http_headers.update(client.settings.extra_http_headers)