0

I want to instantiate an anonymous type that is defined in a wsdl for a soap API with Python and zeep. For non-anonymous types i simply use a factory like this

    abcinstance = factory.abc('whatever', part2 = 'goes')

and afterwards give it to the function that i need to call

    client.service.doSomethingSpecial(abc = abcinstance)

However here

    abcdinstance = factory.abcd(Entries = ['something', key = 'else'])

doesnt work, because the last '=' is apparently wrong syntax. That a List is required that takes one positional Argument and one named only adds to my confusion. I am quite unfamiliar with Python, but there must be an easy way to solve this, right?

EDIT:

Since you cant see the generated code by zeep. The relevant code part as generated by wsdl.exe in c#:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "qwertz")]
public partial class abc
{

    private abcEntry[] entriesField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("Entry", IsNullable = false)]
    public abcEntry[] Entries
    {
        get
        {
            return this.entriesField;
        }
        set
        {
            this.entriesField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "qwertz")]
public partial class abcEntry
{

    private string keyField;

    private string valueField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string key
    {
        get
        {
            return this.keyField;
        }
        set
        {
            this.keyField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()]
    public string Value
    {
        get
        {
            return this.valueField;
        }
        set
        {
            this.valueField = value;
        }
    }
}

I need to instantiate the class abc to give it to a function

The structure in zeep is a bit different: abc requires the following Signature: Entries: {Entry: {xsd:string, key: xsd:string}[]}

  • Try removing `Entries =`? The actual error message is usually helpful – bendl Dec 11 '17 at 14:22
  • Error is `SyntaxError: invalid syntax` ; Removing `Entries =` doesnt change this – Max Mustermann Dec 11 '17 at 14:33
  • Could you also give a link to the API page you refer to? – bendl Dec 11 '17 at 14:36
  • You mean the wsdl meta file? You need to login to access it, so it is confidential. I have the login, but i sure wont post it :D – Max Mustermann Dec 11 '17 at 14:43
  • Understandable xD Can you post just the relevant snippet? – bendl Dec 11 '17 at 14:44
  • Hope the edit helps – Max Mustermann Dec 11 '17 at 14:57
  • Not offended at all, i do know that they denote a dictionary, however how can i create a dictionary where the first argument has no name? The List meant the [ ] Brackets in the end – Max Mustermann Dec 11 '17 at 15:17
  • I deleted my comment because I realized (I think?) that that last line was generated C# – bendl Dec 11 '17 at 15:18
  • If you mean Signature: Entries: {Entry: {xsd:string, key: xsd:string}[]}, i got that one out of an error if you purposefully give bad information like factory.abc(totalbullshit = 'name') this gives back an error message with a correct signature. – Max Mustermann Dec 11 '17 at 15:22
  • Taking a step back, when a function requires both named and positional arguments [the positional arguments go first, followed by the named ones.](https://stackoverflow.com/a/1419160/5090081) The argument list should not typically be thought of as the data structure, but rather the way an everyday person would think of a list. So I think the way it's asking for input is `abcdinstance = factory.abcd('something', key='else')` – bendl Dec 11 '17 at 15:25
  • This does not work, got an unexpected keyword argument 'key'. Signature: `Entries: {Entry: {xsd:string, key: xsd:string}[]}`. I think the abcdinstance = factory.abcd(Entries = ...) is correct and the ... have to be filled – Max Mustermann Dec 11 '17 at 15:32
  • That's possible. I don't know what keyword should be there, I only used `key` because that's what was written in your example. If you are correct that the correct syntax is `Entries = ...`, then `...` needs to be in basic python syntax - that is, it needs to be either a single element, or either a list or a dictionary. – bendl Dec 11 '17 at 15:38
  • key is the correct keyword for the inner anonymous type, Entries is the correct keyword for the outer type. I think there should be a list, a list that contains the inner anonymous type as objects. However due to them being anonymous i cant declare them seperately, insert them into the list and give the list to the outer type – Max Mustermann Dec 11 '17 at 15:45

0 Answers0