【问题标题】:Soap request with suds does not work肥皂水请求不起作用
【发布时间】:2017-10-13 08:33:07
【问题描述】:

我不得不向这个网络服务发出肥皂请求,但每次我得到一个错误 请求的配偶是这样的:

POST /NewIPGServices/Sale/SaleService.asmx HTTP/1.1
Host: pec.shaparak.ir
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService/SalePaymentRequest"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SalePaymentRequest xmlns="https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService">
      <requestData />
    </SalePaymentRequest>
  </soap:Body>
</soap:Envelope>

这是我的代码:

def ps_pymnt(request):
    location ="https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService"
    PS_webService = "‫‪https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx‬‬"
    client=Client(PS_webService,location=location) #from suds.client import Client
    print(client)
    .
    .
    .
    return something

在代码到达打印行之前我有这个错误:

Request Method: GET
Request URL: http://127.0.0.1:8002/payment/ps/pay/

Traceback:

File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
packages/django/core/handlers/base.py" in get_response
149.                     response = 
self.process_exception_by_middleware(e, request)

File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
packages/django/core/handlers/base.py" in get_response
147.                     response = wrapped_callback(request, 
*callback_args, **callback_kwargs)

File "/home/salman/salman/Projects/vira05/vira-285-
parsianPayment/virasciencecom/payment/views.py" in ps_port_payment
298.     client = Client(PS_webService, location=location)

 File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
 packages/suds/client.py" in __init__
 111.         self.wsdl = reader.open(url)

 File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
 packages/suds/reader.py" in open
 151.             d = self.fn(url, self.options)

 File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
 packages/suds/wsdl.py" in __init__
 135.         d = reader.open(url)

 File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
 packages/suds/reader.py" in open
  78.             d = self.download(url)

File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
packages/suds/reader.py" in download
  94.             fp = self.options.transport.open(Request(url))

File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
packages/suds/transport/http.py" in open
  174.         return HttpTransport.open(self, request)

File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
packages/suds/transport/http.py" in open
  63.             return self.u2open(u2request)

File "/home/salman/salman/Projects/vira04/virtual/lib/python3.5/site-
packages/suds/transport/http.py" in u2open
  119.             return url.open(u2request, timeout=tm)

File "/usr/lib/python3.5/urllib/request.py" in open
  466.         response = self._open(req, data)

 File "/usr/lib/python3.5/urllib/request.py" in _open
  489.                                 'unknown_open', req)

 File "/usr/lib/python3.5/urllib/request.py" in _call_chain
  444.             result = func(*args)

File "/usr/lib/python3.5/urllib/request.py" in unknown_open
   1324.         raise URLError('unknown url type: %s' % type)

Exception Type: URLError at /payment/ps/pay/
Exception Value: <urlopen error unknown url type: ‫‪https>

这是我第一次使用泡沫,所以也许我犯了一个愚蠢的错误 我在做什么错?有更好的方法用 python 发送肥皂动作?

【问题讨论】:

    标签: python web-services soap suds


    【解决方案1】:

    您可以尝试使用requests。如果您还没有安装请求,您可以使用 pip 工具安装它

    pip install requests

    并发送 GET 请求

    import requests
    
    host = "‫‪https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx‬‬"
    length = len(data)
    headers = { 'Host'          : 'pec.shaparak.ir',
                'Content-Type'  : 'text/xml',
                'Encoding'      : 'utf-8',
                'Content-Length': length}
    
    resp = requests.request("GET", host, data=data, headers=headers)
    

    您可以使用resp.status_code 获取请求响应HTTP 代码,使用resp.content 获取完整响应。如果需要原始数据,请在请求中添加stream=True 参数并使用resp.raw.read(10) 读取10 个字节的响应,或使用resp.raw.data 读取所有响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多