I tried to integrate a web service (aramex tracking shipments) with my python application, they offer an example in php and I test it .. all is well, but when I turn it into python I encountered a problem to transform a array in python... ('Shipments' => array('XXXXXXXXXX')
), Always return:
'Notifications': {
'Notification': [
{
'Code': 'REQ39',
'Message': 'Shipments - Shipments List is empty'
}
They offered another service "create shipment" and I integrate it into my application without any problem.
I tried this solutions:
Shipment = ['XXXXXXXXXX']
Shipment = ['XXXXXXXXXX',]
Shipment = ('XXXXXXXXXX',)
Shipment = {['XXXXXXXXXX']}
Shipment = {['XXXXXXXXXX',]}
This is the web service in PHP:
<?php
$soapClient = new SoapClient('Tracking.wsdl');
echo '<pre>';
// shows the methods coming from the service
print_r($soapClient->__getFunctions());
/*
parameters needed for the trackShipments method , client info, Transaction, and Shipments' Numbers.
Note: Shipments array can be more than one shipment.
*/
$params = array(
'ClientInfo' => array(
'AccountCountryCode' => 'JO',
'AccountEntity' => 'AMM',
'AccountNumber' => 'NNNNN',
'AccountPin' => 'NNNNNN',
'UserName' => 'AAAA@AAA.com',
'Password' => 'XXXXXXXXX',
'Version' => 'v1.0'
),
'Transaction' => array(
'Reference1' => '001'
),
'Shipments' => array(
'XXXXXXXXXX'
)
);
// calling the method and printing results
try {
$auth_call = $soapClient->TrackShipments($params);
} catch (SoapFault $fault) {
die('Error : ' . $fault->faultstring);
}
?>
And this is my python code:
from zeep import Client
client = Client('https://ws.dev.aramex.net/ShippingAPI.V2/Tracking/Service_1_0.svc?wsdl')
ClientInfo = {'UserName':'xx@xx.xx', 'Password':'xxxxx',
'Version':'v1.0', 'AccountNumber':'xxxxxx', 'AccountPin':'xxxxxx',
'AccountEntity':'xxx', 'AccountCountryCode':'xx'}
Transaction = {'Reference1': 'xxxx'}
Shipments = ('xxxxxxxxxxx',)
GetLastTrackingUpdateOnly = False
print(client.service.TrackShipments(ClientInfo,Transaction,Shipments,GetLastTrackingUpdateOnly))
And this is the error:
{
'Transaction': {
'Reference1': 'xxxxx',
'Reference2': None,
'Reference3': None,
'Reference4': None,
'Reference5': None
},
'Notifications': {
'Notification': [
{
'Code': 'REQ39',
'Message': 'Shipments - Shipments List is empty'
}
]
},
'HasErrors': True,
'TrackingResults': None,
'NonExistingWaybills': None
}
any idea? Thanks a lot
A PHP array
serves as both a dict
and a list
, depending on whether it contains explicit keys or not (in fact, even a combination is possible, which has no analogue on Python). So the equivalent of:
array('Shipments' => array('XXXXXXXXXX'))
is:
{'Shipments': ['XXXXXXXXX']}