Bingads SDK Python Suds 发送了错误的信封

Bingads SDK Python Suds sending wrong envelope

使用 BingAds SDK Python 由于一个我无法解决的错误,我无法执行任何更新操作。 SDK 使用 Suds 处理 SOAP 操作。

这是 wsdl: https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/CampaignManagementService.svc?singleWsdl

# This function internally configures the authorization for BingAdsAPI
campaign_service = bc.get_bing_ads_client(account=account, service='CampaignManagementService')

update_ad_groups_request = campaign_service.factory.create('UpdateAdGroupsRequest')
update_ad_groups_request.CampaignId = campaign_id

ad_group = campaign_service.factory.create('AdGroup')
ad_group.Id = ad_group_id

bid = campaign_service.factory.create('Bid')

bid.Amount = new_bid
ad_group.CpcBid = bid

update_ad_groups_request.AdGroups = campaign_service.factory.create('ArrayOfAdGroup')

update_ad_groups_request.AdGroups.AdGroup.append(ad_group)

campaign_service.UpdateAdGroups(update_ad_groups_request)

当我发送它时失败说:

suds.WebFault: Server raised fault: 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/CampaignManagement/v13:CampaignId. The InnerException message was 'There was an error deserializing the object of type System.Int64. The value '' cannot be parsed as the type 'Int64'.'. Please see InnerException for more details.'

当我打开肥皂信封时:

....</SOAP-ENV:Header><ns1:Body><ns0:UpdateAdGroupsRequest><ns0:CampaignId>
<ns0:CampaignId>377072652</ns0:CampaignId><ns0:AdGroups><ns0:AdGroup><ns0:CpcBid>
<ns0:Amount>0.91</ns0:Amount></ns0:CpcBid><ns0:Id>1256742239729725</ns0:Id>
<ns0:Network/><ns0:PrivacyStatus/><ns0:Status/></ns0:AdGroup></ns0:AdGroups>
</ns0:CampaignId></ns0:UpdateAdGroupsRequest></ns1:Body></SOAP-ENV:Envelope>

请注意活动 ID 是如何重复的,并且它包裹了整个信封。我也直接用 Suds 试过,我有同样的问题,其他功能也有同样的问题。

因为要自己解析信封,所以我想知道是否有人遇到过这个问题,可能是什么原因。

您不需要显式创建 'Request' 对象,即通过 SUDS 服务客户端,您可以通过 UpdateAdGroups 操作直接传递请求参数。为了确认我从 expanded_text_ads.py and inserted the following snippet immediately after the AddAdGroups 示例开始。

ad_groups=campaign_service.factory.create('ArrayOfAdGroup')
ad_group=set_elements_to_none(campaign_service.factory.create('AdGroup'))
ad_group.Id=ad_group_ids['long'][0]
cpc_bid=campaign_service.factory.create('Bid')
cpc_bid.Amount=0.11
ad_group.CpcBid=cpc_bid
ad_groups.AdGroup.append(ad_group)

output_status_message("-----\nUpdateAdGroups:")
add_ad_groups_response=campaign_service.UpdateAdGroups(
    CampaignId=campaign_ids['long'][0],
    AdGroups=ad_groups
)
output_status_message("PartialErrors:")
output_array_of_batcherror(add_ad_groups_response.PartialErrors)

希望对您有所帮助!如果您有任何后续问题,请告诉我。