如何将Aramex API与WSDL和Python结合使用? [英] How can I use the Aramex API with WSDL and Python?

查看:94
本文介绍了如何将Aramex API与WSDL和Python结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在他们的网站上找到了一些有关Aramex运输服务及其运输API的PHP示例代码.我正在测试我的API凭据,但是下面出现了错误.

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.

这是示例代码:

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)

这是包含错误的输出:

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

我正在测试URL API,我想我需要添加一个在此处获得的证书.如何在Suds中添加证书?

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?

推荐答案

问题是通过使用https而不是http

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

这篇关于如何将Aramex API与WSDL和Python结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆