How can I use the Aramex API with WSDL and Python?

ぃ、小莉子 提交于 2019-12-13 05:53:55

问题


I found some PHP example code about the Aramex Shipping services and their shipping API on their website. I'm testing my API credentials, but I'm getting the error below.

Here is the example code:

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 = 'testingapi@aramex.com'
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)

This is the output containing the error:

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

I am testing the URL API and I think I need to add a certificate which is given here. How can I add certificates in Suds?


回答1:


Problem is solved by using https instead of http

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


来源:https://stackoverflow.com/questions/37741512/how-can-i-use-the-aramex-api-with-wsdl-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!