首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Aramex与WSDL和Python结合使用?

如何将Aramex与WSDL和Python结合使用?
EN

Stack Overflow用户
提问于 2016-06-10 06:41:02
回答 1查看 1.3K关注 0票数 0

我在他们的网站上找到了一些关于Aramex航运服务及其发货API的PHP示例代码。我正在测试我的API凭据,但下面是错误信息。

下面是示例代码:

代码语言:javascript
复制
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)

这是包含错误的输出:

代码语言:javascript
复制
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,我认为我需要添加一个被授予这里的证书。如何在Suds中添加证书?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-10 13:35:33

通过使用https而不是http来解决问题。

代码语言:javascript
复制
client.sd[0].service.setlocation('https://ws.dev.aramex.net/shippingapi/shipping/service_1_0.svc')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37741512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档