Pyhton - 从 Python 调用带有 WSDL、有效负载和基本身份验证的 SOAP API

发布于 2025-01-21 03:02:42 字数 664 浏览 0 评论 0原文

我正在尝试使用 WSDL 调用 SOAP API、请求 PAYLOAD、使用 Python 中的用户名和密码进行基本身份验证。

下面给出了代码 spinet。但无法进行身份验证,但 SOAPUI 中可以使用相同的用户名和密码。 回复还包含一个附件。 帮助我如何通过一些示例代码获取该附件。

import base64    
import requests  
from requests.structures import CaseInsensitiveDict    
from requests.auth import HTTPBasicAuth    
url = "https://WSDL URL"    
headersVal = CaseInsensitiveDict()    
headersVal["Content-Type"] = "application/soap+xml"    
headersVal["Authorization"] = 'Basic %s' % base64.b64encode("username:password")    
data = """request Payload"""    
resp = requests.post(url, headers=headersVal, data=data)    
print(resp.status_code)    

谢谢 安尼什

I am attempting to call SOAP API with WSDL, request PAYLOAD, basic authentication using user name and password from Python.

Code spinet is given below. But it is failing to authenticate but same user name and password is working in SOAPUI.
Also response contain one attachment.
Help me how to get that attachment with some example code.

import base64    
import requests  
from requests.structures import CaseInsensitiveDict    
from requests.auth import HTTPBasicAuth    
url = "https://WSDL URL"    
headersVal = CaseInsensitiveDict()    
headersVal["Content-Type"] = "application/soap+xml"    
headersVal["Authorization"] = 'Basic %s' % base64.b64encode("username:password")    
data = """request Payload"""    
resp = requests.post(url, headers=headersVal, data=data)    
print(resp.status_code)    

Thanks
Anish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十六岁半 2025-01-28 03:02:42

尝试使用此。如果这不起作用,请让我知道错误。

from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport

url = "https://WSDL URL"    
username = "username"
password = "password"

session = Session()
session.auth = HTTPBasicAuth(username, password)
client = Client(wsdl, transport=Transport(session=session))
  
resp = client.service.Payload()    
print(resp.status_code)   

Try using this. If this doesn't work let me know the error.

from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport

url = "https://WSDL URL"    
username = "username"
password = "password"

session = Session()
session.auth = HTTPBasicAuth(username, password)
client = Client(wsdl, transport=Transport(session=session))
  
resp = client.service.Payload()    
print(resp.status_code)   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文