2016-06-10 18 views
0

Ich habe einige PHP-Beispiel-Code über die Aramex Shipping-Dienste und ihre Versand-API auf ihrer Website gefunden. Ich teste meine API-Anmeldedaten, aber ich erhalte den Fehler unten. HierWie kann ich die Aramex-API mit WSDL und Python verwenden?

ist der Beispielcode:

import xml, fpconst, logging 
from SOAPpy import WSDL 
from suds.client import Client 

logging.basicConfig(level=logging.INFO) 
logging.getLogger('suds.client').setLevel(logging.DEBUG) 
url = "http://localhost/shipping-services-api-wsdl.wsdl" 

client = Client(url) 

client.sd[0].service.setlocation('http://ws.dev.aramex.net/shippingapi/shipping/service_1_0.svc') 

clientobj = client.factory.create('ClientInfo') 
clientobj.UserName = '[email protected]' 
clientobj.Password = 'R123456789$r' 
clientobj.Version = 'v1.0' 
clientobj.AccountNumber = '20016' 
clientobj.AccountPin = '331421' 
clientobj.AccountEntity = 'AMM' 
clientobj.AccountCountryCode = 'JO' 

transactionobj = client.factory.create('Transaction') 
transactionobj.Reference1 = 'PRINT_LABEL_1441457996' 
transactionobj.Reference2 = '' 
transactionobj.Reference3 = '' 
transactionobj.Reference4 = '' 
transactionobj.Reference5 = '' 

labelinfoobj = client.factory.create('LabelInfo') 
labelinfoobj.ReportID = '9201' 
labelinfoobj.ReportType = 'url' 

print client.service.PrintLabel(clientobj,transactionobj,"001","EXP","",labelinfoobj) 

Dies ist die Ausgabe enthält den Fehler:

DEBUG:suds.client:sending to (http://ws.dev.aramex.net/shippingapi/shipping/service_1_0.svc) 
message: 
<suds.sax.document.Document instance at 0x7f019a069b90> 
DEBUG:suds.client:headers = {'SOAPAction': '"http://ws.aramex.net/ShippingAPI/v1/Service_1_0/PrintLabel"', 'Content-Type': 'text/xml; charset=utf-8'} 
DEBUG:suds.client:HTTP failed - 403 - Forbidden: 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
<title>403 - Forbidden: Access is denied.</title> 
<style type="text/css"> 
<!-- 
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} 
fieldset{padding:0 15px 10px 15px;} 
h1{font-size:2.4em;margin:0;color:#FFF;} 
h2{font-size:1.7em;margin:0;color:#CC0000;} 
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; 
background-color:#555555;} 
#content{margin:0 0 0 2%;position:relative;} 
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} 
--> 
</style> 
</head> 
<body> 
<div id="header"><h1>Server Error</h1></div> 
<div id="content"> 
<div class="content-container"><fieldset> 
    <h2>403 - Forbidden: Access is denied.</h2> 
    <h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3> 
</fieldset></div> 
</div> 
</body> 
</html> 

ERROR:suds.client:<suds.sax.document.Document instance at 0x7f019a069b90> 
Traceback (most recent call last): 
    File "test.py", line 33, in <module> 
    print client.service.PrintLabel(clientobj,transactionobj,"001","EXP","",labelinfoobj) 
    File "/home/harish/Desktop/aramax/env/local/lib/python2.7/site-packages/suds/client.py", line 521, in __call__ 
    return client.invoke(args, kwargs) 
    File "/home/harish/Desktop/aramax/env/local/lib/python2.7/site-packages/suds/client.py", line 581, in invoke 
    result = self.send(soapenv) 
    File "/home/harish/Desktop/aramax/env/local/lib/python2.7/site-packages/suds/client.py", line 619, in send 
    description=tostr(e), original_soapenv=original_soapenv) 
    File "/home/harish/Desktop/aramax/env/local/lib/python2.7/site-packages/suds/client.py", line 677, in process_reply 
    raise Exception((status, description)) 
Exception: (403, u'Forbidden') 

ich die URL API mich entschieden, und ich glaube, ich brauche ein Zertifikat hinzufügen, die gegeben ist here. Wie kann ich Zertifikate in Suds hinzufügen?

Antwort

0

Problem wird durch die Verwendung https statt http

client.sd[0].service.setlocation('https://ws.dev.aramex.net/shippingapi/shipping/service_1_0.svc') 
gelöst