0

I am using Zeep to try and interact with a SOAP client on SellerCloud. When I pass in my argument for one of the API's operations, I get hit with a ValueError -

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

Here is the relevant code:

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)

And the stack trace error -

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

And the output of my print statements prior to where the error is happening -

{
    '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

I've been banging my head on this for a while but can't seem to find where this whole length of 15 deal is happening. Even if I pass in an empty array like : filters = filters_type([]), I still get a length of 15 error.

demluckycharms
  • 421
  • 1
  • 6
  • 17
  • My guess, and it's hard to say from this example, but I think the filters need to be passed as a dictionary of key-value pairs. i.e. `{'DateFrom': '2018...'}` – pypypy Oct 16 '18 at 22:43
  • Yeah, I tried that as well. Passing a dictionary directly into `client.service.Orders_Get(filters)` and bypassing the `filters_type` step gives the same error. – demluckycharms Oct 16 '18 at 22:47

1 Answers1

1

Based on the traceback it is failing when updating HTTP headers here:

http_headers.update(client.settings.extra_http_headers)

I would investigate if extra_http_headers=sc_auth sets the right headers. It looks like you need to pass there plain HTTP headers (a dict) and you are giving it some SOAP structure.

Santiago Bruno
  • 461
  • 2
  • 9
  • Looks like that might be it. Now I'm running into a new problem, though. The `client.service.Orders_Get()` apparently needs the specific SOAP structure to authenticate properly, which from the API's docs looks like `Orders_Get(SCAuth, SCSettings, filters)`. Unfortunately, passing in more than one argument here throws an error saying only one argument is allowed. – demluckycharms Oct 16 '18 at 23:07
  • 1
    Error message stating need for auth in the method call - `zeep.exceptions.Fault: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: Please provide authentication information in AuthHeaderValue property of service object.` – demluckycharms Oct 16 '18 at 23:11
  • 1
    Not sure. Take a look at this docs: https://python-zeep.readthedocs.io/en/master/headers.html Probably you need to call `Orders_Get` with `_soapheaders` named parameter and the auth information you have. – Santiago Bruno Oct 16 '18 at 23:17
  • Using the `_soapheaders` definitely helps. Looks like the authentication process is now starting correctly. Sure enough, now I'm getting told my username is invalid - despite it being copy / pasted. That's a problem that can't really be fixed though, so I'll be marking your solution as correct! Thanks! – demluckycharms Oct 17 '18 at 16:15