python - 在 python 中调用 SOAP 客户端(suds) 返回错误 AuthenticationError.LOGIN_COOKIE_REQUIRED

标签 python api soap suds

我在 python 中已经 1 周大了。 我从 python 调用 sudssoap api 。 这是我的代码。

logging.basicConfig(level=logging.INFO)
if __debug__:
    logging.getLogger('suds.client').setLevel(logging.DEBUG)
else:
    logging.getLogger('suds.client').setLevel(logging.CRITICAL)
client = Client(wsdlurl, soapheaders='string')
# Create ClientCustomerId parameter value for mutate method
clientId = client.factory.create("ClientCustomerId")
product = client.factory.create("Product")
clientId.product = product.INVITE_ADVERTISER
clientId.entityId = XXXX

# Create UserListOperation parameter value for mutate method
# Create UserList Object
userList = client.factory.create("UserList")
millis = int(round(time.time() * 1000))
userList.name = "Demographic segment # %s" % millis
userList.description = "Target dempographic description"
userList.integrationCode = "XXX"
d = timedelta(days=365)
userList.membershipLifeSpan = d.days
userListOperation = client.factory.create("UserListOperation")
userListOperation.operand = userList
operator = client.factory.create("Operator")
userListOperation.operator = operator.ADD
print userListOperation
operations = [userListOperation]
result = client.service.mutate(clientId, userListOperation)  //Error raises here
print result

在调用 mutate() 方法时出现错误,如服务器引发错误:'[AuthenticationError.LOGIN_COOKIE_REQUIRED @ ;触发器:'']'

在客户端方法中,我添加了 SOAP 头,例如 client = Client(wsdlurl,soapheaders='string'),否则我会收到错误“缺少 SOAP 头”

由于登录 cookie 错误,尝试传递访问 token 但没有任何效果。 client = Client(wsdlurl,headers{'key':'value'},soapheaders='string')#,soapheaders{'userAgent':'administrator'})

#atoken = Element('token').setText(token)
#locale = Element('locale').setText('en')
#client.set_options(soapheaders=(atoken,locale))

浏览了很多,但似乎没有什么用处。 有什么帮助吗??

最佳答案

终于我找到了解决方案,可能对任何初学者都有用。

使用 suds 模块调用 SOAP API 时,我们需要设置 header ,在我的例子中,我通过 OAuth 身份验证传递访问 token ,如下所示

code='Bearer %s'%accToken
headers={'Authorization':code}
client = Client(wsdlurl,headers=headers,soapheaders=(appname))

这里 accToken 是我的访问 token ,headers 是一个字典,我传递的键是“Authorization”,值是“Bearer XXX(accToken)”,appname 是我的应用程序名称(只是一个字符串)

干杯

关于python - 在 python 中调用 SOAP 客户端(suds) 返回错误 AuthenticationError.LOGIN_COOKIE_REQUIRED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36352790/

相关文章:

python - 使用 NTLM 验证 Lists.asmx?WSDL 后如何让 Suds 运行代理?

python - 箱形图的 x 标签已移动

javascript - 如何更改 Darksky API 请求的时间格式?

php - 如何在 laravel 中从一个函数开始事务并在另一个函数中结束它

ios - alamofire 通过 SOAP 发送请求

wcf - 记录 WCF 服务收到的请求

python - 展平多态模型

python - 我可以使用哪个 IronPython 编辑器为 Tibco Spotfire 控件开发脚本

python - Django 将查询集序列化为 JSON 以仅使用字段信息和 id 构造 RESTful 响应

java - 在服务器上以编程方式添加拦截器