SOAPpy.Types.faultType: Cannot use object of type stdClass as array

Chris Angelico rosuav at gmail.com
Sat Mar 23 21:55:00 CET 2013


On Sun, Mar 24, 2013 at 6:38 AM, Tamer Higazi <th982a at googlemail.com> wrote:
> Chris!
> I did what you said before in several ways.
>
> The last way was putting the user and password directly into the dict as
> parameter ALWAYS ends up telling me, that I cannot use object of
> standard type class as ARRAY....
>
> I did it this time with suds. So packaging issue is now out of scope,
> and always the same headache.
>
>
> now tell me what this error might tell me:
>
>
> suds.WebFault: Server raised fault: 'Cannot use object of type stdClass
> as array'

So it's the same error this way, too. That error came back from the
server, and is being quoted verbatim. That means that, ultimately, the
problem is in the XML blob that you're sending it; the trick is to
figure out what exactly the server isn't happy with.

(Aside: The server is at least partly at fault here. It should be
giving more useful error messages. But I'm assuming you don't have any
control over the server.)

I tried the reference PHP implementation off the web site, and it's
coming back with 500 Internal Server Error with body of text/html,
which is clearly buggy documentation. When I change it to use the WSDL
you're using, I can actually get something plausible out of it.

Modified PHP code:

<?php

// URIs zu den WSDL-Dateien
$WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl';
//$WSDL_API = 'https://kasserver.com/schnittstelle/soap/wsdl/KasApi.wsdl';

// Logindaten
$kas_user = 'w001234';  // KAS-Logon
$kas_pass = 'xxxxxxx';  // KAS-Passwort
$session_lifetime = 1800;  // Gültigkeit des Tokens in Sek. bis zur
neuen Authentifizierung
$session_update_lifetime = 'Y'; // Soll bei jeder Aktion die
Sessionlifetime wieder auf den
//                                   Wert in "$session_lifetime"
gesetzt werden? ('Y' / 'N')
try
{
  $SoapLogon = new SoapClient($WSDL_AUTH,["trace"=>1]);  // url zur wsdl - Datei
  $CredentialToken = $SoapLogon->KasAuth(
                          array('KasUser' => $kas_user,
                                'KasAuthType' => 'sha1',
                                'KasPassword' => sha1($kas_pass),
                                'SessionLifeTime' => $session_lifetime,
                                'SessionUpdateLifeTime' =>
$session_update_lifetime
                          )
                        );
}

// Fehler abfangen und ausgeben
catch (SoapFault $fault)
{
    echo "Request:\n".$SoapLogon->__getLastRequestHeaders()."\n".$SoapLogon->__getLastRequest()."\n";
    echo "Response:\n".$SoapLogon->__getLastResponseHeaders()."\n".$SoapLogon->__getLastResponse()."\n";
    trigger_error("Fehlernummer: {$fault->faultcode},
                    Fehlermeldung: {$fault->faultstring},
                    Verursacher: {$fault->faultactor},
                    Details: {$fault->detail}", E_USER_ERROR);
}



(Another aside: Until I added the two echo lines, this had a try/catch
that simply triggered a fatal error. This is pointless. Just let the
error happen!)

Here's the packet the PHP code sends:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:xmethodsKasApiAuthentication"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://xml.apache.org/xml-soap"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:KasAuth><Params
xsi:type="ns2:Map"><item><key
xsi:type="xsd:string">KasUser</key><value
xsi:type="xsd:string">w001234</value></item><item><key
xsi:type="xsd:string">KasAuthType</key><value
xsi:type="xsd:string">sha1</value></item><item><key
xsi:type="xsd:string">KasPassword</key><value
xsi:type="xsd:string">2db6d21d365f544f7ca3bcfb443ac96898a7a069</value></item><item><key
xsi:type="xsd:string">SessionLifeTime</key><value
xsi:type="xsd:int">1800</value></item><item><key
xsi:type="xsd:string">SessionUpdateLifeTime</key><value
xsi:type="xsd:string">Y</value></item></Params></ns1:KasAuth></SOAP-ENV:Body></SOAP-ENV:Envelope>

Here's what your original Python version sends, lifted via tcpdump as
I'm not sufficiently familiar with soappy to get a full packet dump
out of it:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<ns1:KasAuth xmlns:ns1="urn:xmethodsKasApiAuthentication" SOAP-ENC:root="1">
<v1>
<SessionUpdateLifeTime xsi:type="xsd:string">Y</SessionUpdateLifeTime>
<KasAuthType xsi:type="xsd:string">sha1</KasAuthType>
<SessionLifeTime xsi:type="xsd:int">1800</SessionLifeTime>
<KasUser xsi:type="xsd:string">login</KasUser>
<KasPassword xsi:type="xsd:string">5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8</KasPassword>
</v1>
</ns1:KasAuth>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And here's what your latest Python sends, lifted the same way for the
same reason regarding suds:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
xmlns:ns3="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns0="urn:xmethodsKasApiAuthentication"
xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns4="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><ns2:Body><ns0:KasAuth><Params
xsi:type="ns1:Params"><SessionUpdateLifeTime
xsi:type="ns3:string">Y</SessionUpdateLifeTime><KasAuthType
xsi:type="ns3:string">sha1</KasAuthType><SessionLifeTime
xsi:type="ns3:int">1800</SessionLifeTime><KasUser
xsi:type="ns3:string">userlogin</KasUser><KasPassword
xsi:type="ns3:string">45f106ef4d5161e7aa38cf6c666607f25748b6ca</KasPassword></Params></ns0:KasAuth></ns2:Body></SOAP-ENV:Envelope>


The PHP version comes back with a fault string
"kas_password_incorrect", which is what I would expect. The Python
ones both show the PHP crash you described. I'm seeing quite a few
differences between the three; figuring out what's the cause of the
crash will be a matter of fiddling until you discover it.

I would recommend, at least for testing, bypassing the whole SOAP
library layer and putting XML data straight into HTTP requests. And
maybe you'll find that's the easiest option for production code, too;
I've done exactly that at work, talking to SOAP servers at eBay and
other sites. Building up XML isn't difficult, and it's generally
easier to have less layers to debug.

Hope that's of at least some value to you. It looks likely the
server's largely to blame for this.

ChrisA



More information about the Python-list mailing list