了解如何与zeep服务响应进行交互

时间:2019-03-06 15:13:48

标签: python-2.7 soap sharepoint-2013 zeep

所以我试图弄清楚如何与SharePoint交互。我尝试休息失败了。您可以看到我的问题here。因此,从响应和网上浏览中,我可以看到其他人也遇到了同样的问题,但没有明确的解决方案。还有另一种使用jQuery包SPservices的选项,但是我想写的不是用于网络的...

我现在正在尝试使用SharePoints soap API。这是我到目前为止的代码:

from zeep import Client
from zeep.transports import Transport
from requests_ntlm import HttpNtlmAuth
from requests import Session
wsdl_url = "sharepointsite/_vti_bin/Lists.asmx?WSDL"

session = Session()
session.auth = HttpNtlmAuth('user','password')



soap_client = Client(wsdl_url, transport=Transport(session=session))
result = soap_client.service.GetListCollection()

所以结果是某种我不确定如何处理的对象。当我打印结果变量时,这就是我得到的:

<Element {http://schemas.microsoft.com/sharepoint/soap/}Lists at 0x4f1b988>

所以我的第一个问题是如何与这个Element对象交互?

我的第二个问题是,我如何知道其余具有输入功能的soap函数的正确语法是什么?我已经弄清楚如何创建wsdl文件soap_client.wsdl.dump().的转储,下面是转储:

Prefixes:
     ns0: http://schemas.microsoft.com/sharepoint/soap/
     ns1: http://microsoft.com/wsdl/types/
     xsd: http://www.w3.org/2001/XMLSchema

Global elements:
     ns0:AddAttachment(listName: xsd:string, listItemID: xsd:string, fileName: xsd:string, attachment: xsd:base64Binary)
     ns0:AddAttachmentResponse(AddAttachmentResult: xsd:string)
     ns0:AddDiscussionBoardItem(listName: xsd:string, message: xsd:base64Binary)
     ns0:AddDiscussionBoardItemResponse(AddDiscussionBoardItemResult: {_value_1: ANY})
     ns0:AddList(listName: xsd:string, description: xsd:string, templateID: xsd:int)
     ns0:AddListFromFeature(listName: xsd:string, description: xsd:string, featureID: ns1:guid, templateID: xsd:int)
     ns0:AddListFromFeatureResponse(AddListFromFeatureResult: {_value_1: ANY})
     ns0:AddListResponse(AddListResult: {_value_1: ANY})
     ns0:AddWikiPage(strListName: xsd:string, listRelPageUrl: xsd:string, wikiContent: xsd:string)
     ns0:AddWikiPageResponse(AddWikiPageResult: {_value_1: ANY})
     ns0:ApplyContentTypeToList(webUrl: xsd:string, contentTypeId: xsd:string, listName: xsd:string)
     ns0:ApplyContentTypeToListResponse(ApplyContentTypeToListResult: {_value_1: ANY})
     ns0:CheckInFile(pageUrl: xsd:string, comment: xsd:string, CheckinType: xsd:string)
     ns0:CheckInFileResponse(CheckInFileResult: xsd:boolean)
     ns0:CheckOutFile(pageUrl: xsd:string, checkoutToLocal: xsd:string, lastmodified: xsd:string)
     ns0:CheckOutFileResponse(CheckOutFileResult: xsd:boolean)
     ns0:CreateContentType(listName: xsd:string, displayName: xsd:string, parentType: xsd:string, fields: {_value_1: ANY}, contentTypeProperties: {_value_1: ANY}, addToView: xsd:string)
     ns0:CreateContentTypeResponse(CreateContentTypeResult: xsd:string)
     ns0:DeleteAttachment(listName: xsd:string, listItemID: xsd:string, url: xsd:string)
     ns0:DeleteAttachmentResponse()
     ns0:DeleteContentType(listName: xsd:string, contentTypeId: xsd:string)
     ns0:DeleteContentTypeResponse(DeleteContentTypeResult: {_value_1: ANY})
     ns0:DeleteContentTypeXmlDocument(listName: xsd:string, contentTypeId: xsd:string, documentUri: xsd:string)
     ns0:DeleteContentTypeXmlDocumentResponse(DeleteContentTypeXmlDocumentResult: {_value_1: ANY})
     ns0:DeleteList(listName: xsd:string)
     ns0:DeleteListResponse()
     ns0:GetAttachmentCollection(listName: xsd:string, listItemID: xsd:string)
     ns0:GetAttachmentCollectionResponse(GetAttachmentCollectionResult: {_value_1: ANY})
     ns0:GetList(listName: xsd:string)
     ns0:GetListAndView(listName: xsd:string, viewName: xsd:string)
     ns0:GetListAndViewResponse(GetListAndViewResult: {_value_1: ANY})
     ns0:GetListCollection()
     ns0:GetListCollectionResponse(GetListCollectionResult: {_value_1: ANY})
     ns0:GetListContentType(listName: xsd:string, contentTypeId: xsd:string)
     ns0:GetListContentTypeResponse(GetListContentTypeResult: {_value_1: ANY})
     ns0:GetListContentTypes(listName: xsd:string, contentTypeId: xsd:string)
     ns0:GetListContentTypesAndProperties(listName: xsd:string, contentTypeId: xsd:string, propertyPrefix: xsd:string, includeWebProperties: xsd:boolean)
     ns0:GetListContentTypesAndPropertiesResponse(GetListContentTypesAndPropertiesResult: {_value_1: ANY})
     ns0:GetListContentTypesResponse(GetListContentTypesResult: {_value_1: ANY})
     ns0:GetListItemChanges(listName: xsd:string, viewFields: {_value_1: ANY}, since: xsd:string, contains: {_value_1: ANY})
     ns0:GetListItemChangesResponse(GetListItemChangesResult: {_value_1: ANY})
     ns0:GetListItemChangesSinceToken(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, changeToken: xsd:string, contains: {_value_1: ANY})
     ns0:GetListItemChangesSinceTokenResponse(GetListItemChangesSinceTokenResult: {_value_1: ANY})
     ns0:GetListItemChangesWithKnowledge(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, syncScope: xsd:string, knowledge: {_value_1: ANY}, contains: {_value_1: ANY})
     ns0:GetListItemChangesWithKnowledgeResponse(GetListItemChangesWithKnowledgeResult: {_value_1: ANY})
     ns0:GetListItems(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, webID: xsd:string)
     ns0:GetListItemsResponse(GetListItemsResult: {_value_1: ANY})
     ns0:GetListResponse(GetListResult: {_value_1: ANY})
     ns0:GetVersionCollection(strlistID: xsd:string, strlistItemID: xsd:string, strFieldName: xsd:string)
     ns0:GetVersionCollectionResponse(GetVersionCollectionResult: {_value_1: ANY})
     ns0:UndoCheckOut(pageUrl: xsd:string)
     ns0:UndoCheckOutResponse(UndoCheckOutResult: xsd:boolean)
     ns0:UpdateContentType(listName: xsd:string, contentTypeId: xsd:string, contentTypeProperties: {_value_1: ANY}, newFields: {_value_1: ANY}, updateFields: {_value_1: ANY}, deleteFields: {_value_1: ANY}, addToView: xsd:string)
     ns0:UpdateContentTypeResponse(UpdateContentTypeResult: {_value_1: ANY})
     ns0:UpdateContentTypeXmlDocument(listName: xsd:string, contentTypeId: xsd:string, newDocument: {_value_1: ANY})
     ns0:UpdateContentTypeXmlDocumentResponse(UpdateContentTypeXmlDocumentResult: {_value_1: ANY})
     ns0:UpdateContentTypesXmlDocument(listName: xsd:string, newDocument: {_value_1: ANY})
     ns0:UpdateContentTypesXmlDocumentResponse(UpdateContentTypesXmlDocumentResult: {_value_1: ANY})
     ns0:UpdateList(listName: xsd:string, listProperties: {_value_1: ANY}, newFields: {_value_1: ANY}, updateFields: {_value_1: ANY}, deleteFields: {_value_1: ANY}, listVersion: xsd:string)
     ns0:UpdateListItems(listName: xsd:string, updates: {_value_1: ANY})
     ns0:UpdateListItemsResponse(UpdateListItemsResult: {_value_1: ANY})
     ns0:UpdateListItemsWithKnowledge(listName: xsd:string, updates: {_value_1: ANY}, syncScope: xsd:string, knowledge: {_value_1: ANY})
     ns0:UpdateListItemsWithKnowledgeResponse(UpdateListItemsWithKnowledgeResult: {_value_1: ANY})
     ns0:UpdateListResponse(UpdateListResult: {_value_1: ANY})


Global types:
     xsd:anyType
     ns1:guid
     xsd:ENTITIES
     xsd:ENTITY
     xsd:ID
     xsd:IDREF
     xsd:IDREFS
     xsd:NCName
     xsd:NMTOKEN
     xsd:NMTOKENS
     xsd:NOTATION
     xsd:Name
     xsd:QName
     xsd:anySimpleType
     xsd:anyURI
     xsd:base64Binary
     xsd:boolean
     xsd:byte
     xsd:date
     xsd:dateTime
     xsd:decimal
     xsd:double
     xsd:duration
     xsd:float
     xsd:gDay
     xsd:gMonth
     xsd:gMonthDay
     xsd:gYear
     xsd:gYearMonth
     xsd:hexBinary
     xsd:int
     xsd:integer
     xsd:language
     xsd:long
     xsd:negativeInteger
     xsd:nonNegativeInteger
     xsd:nonPositiveInteger
     xsd:normalizedString
     xsd:positiveInteger
     xsd:short
     xsd:string
     xsd:time
     xsd:token
     xsd:unsignedByte
     xsd:unsignedInt
     xsd:unsignedLong
     xsd:unsignedShort

Bindings:
     Soap11Binding: {http://schemas.microsoft.com/sharepoint/soap/}ListsSoap
     Soap12Binding: {http://schemas.microsoft.com/sharepoint/soap/}ListsSoap12

Service: Lists
     Port: ListsSoap (Soap11Binding: {http://schemas.microsoft.com/sharepoint/soap/}ListsSoap)
         Operations:
            AddAttachment(listName: xsd:string, listItemID: xsd:string, fileName: xsd:string, attachment: xsd:base64Binary) -> AddAttachmentResult: xsd:string
            AddDiscussionBoardItem(listName: xsd:string, message: xsd:base64Binary) -> AddDiscussionBoardItemResult: {_value_1: ANY}
            AddList(listName: xsd:string, description: xsd:string, templateID: xsd:int) -> AddListResult: {_value_1: ANY}
            AddListFromFeature(listName: xsd:string, description: xsd:string, featureID: ns1:guid, templateID: xsd:int) -> AddListFromFeatureResult: {_value_1: ANY}
            AddWikiPage(strListName: xsd:string, listRelPageUrl: xsd:string, wikiContent: xsd:string) -> AddWikiPageResult: {_value_1: ANY}
            ApplyContentTypeToList(webUrl: xsd:string, contentTypeId: xsd:string, listName: xsd:string) -> ApplyContentTypeToListResult: {_value_1: ANY}
            CheckInFile(pageUrl: xsd:string, comment: xsd:string, CheckinType: xsd:string) -> CheckInFileResult: xsd:boolean
            CheckOutFile(pageUrl: xsd:string, checkoutToLocal: xsd:string, lastmodified: xsd:string) -> CheckOutFileResult: xsd:boolean
            CreateContentType(listName: xsd:string, displayName: xsd:string, parentType: xsd:string, fields: {_value_1: ANY}, contentTypeProperties: {_value_1: ANY}, addToView: xsd:string) -> CreateContentTypeResult: xsd:string
            DeleteAttachment(listName: xsd:string, listItemID: xsd:string, url: xsd:string) -> 
            DeleteContentType(listName: xsd:string, contentTypeId: xsd:string) -> DeleteContentTypeResult: {_value_1: ANY}
            DeleteContentTypeXmlDocument(listName: xsd:string, contentTypeId: xsd:string, documentUri: xsd:string) -> DeleteContentTypeXmlDocumentResult: {_value_1: ANY}
            DeleteList(listName: xsd:string) -> 
            GetAttachmentCollection(listName: xsd:string, listItemID: xsd:string) -> GetAttachmentCollectionResult: {_value_1: ANY}
            GetList(listName: xsd:string) -> GetListResult: {_value_1: ANY}
            GetListAndView(listName: xsd:string, viewName: xsd:string) -> GetListAndViewResult: {_value_1: ANY}
            GetListCollection() -> GetListCollectionResult: {_value_1: ANY}
            GetListContentType(listName: xsd:string, contentTypeId: xsd:string) -> GetListContentTypeResult: {_value_1: ANY}
            GetListContentTypes(listName: xsd:string, contentTypeId: xsd:string) -> GetListContentTypesResult: {_value_1: ANY}
            GetListContentTypesAndProperties(listName: xsd:string, contentTypeId: xsd:string, propertyPrefix: xsd:string, includeWebProperties: xsd:boolean) -> GetListContentTypesAndPropertiesResult: {_value_1: ANY}
            GetListItemChanges(listName: xsd:string, viewFields: {_value_1: ANY}, since: xsd:string, contains: {_value_1: ANY}) -> GetListItemChangesResult: {_value_1: ANY}
            GetListItemChangesSinceToken(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, changeToken: xsd:string, contains: {_value_1: ANY}) -> GetListItemChangesSinceTokenResult: {_value_1: ANY}
            GetListItemChangesWithKnowledge(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, syncScope: xsd:string, knowledge: {_value_1: ANY}, contains: {_value_1: ANY}) -> GetListItemChangesWithKnowledgeResult: {_value_1: ANY}
            GetListItems(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, webID: xsd:string) -> GetListItemsResult: {_value_1: ANY}
            GetVersionCollection(strlistID: xsd:string, strlistItemID: xsd:string, strFieldName: xsd:string) -> GetVersionCollectionResult: {_value_1: ANY}
            UndoCheckOut(pageUrl: xsd:string) -> UndoCheckOutResult: xsd:boolean
            UpdateContentType(listName: xsd:string, contentTypeId: xsd:string, contentTypeProperties: {_value_1: ANY}, newFields: {_value_1: ANY}, updateFields: {_value_1: ANY}, deleteFields: {_value_1: ANY}, addToView: xsd:string) -> UpdateContentTypeResult: {_value_1: ANY}
            UpdateContentTypeXmlDocument(listName: xsd:string, contentTypeId: xsd:string, newDocument: {_value_1: ANY}) -> UpdateContentTypeXmlDocumentResult: {_value_1: ANY}
            UpdateContentTypesXmlDocument(listName: xsd:string, newDocument: {_value_1: ANY}) -> UpdateContentTypesXmlDocumentResult: {_value_1: ANY}
            UpdateList(listName: xsd:string, listProperties: {_value_1: ANY}, newFields: {_value_1: ANY}, updateFields: {_value_1: ANY}, deleteFields: {_value_1: ANY}, listVersion: xsd:string) -> UpdateListResult: {_value_1: ANY}
            UpdateListItems(listName: xsd:string, updates: {_value_1: ANY}) -> UpdateListItemsResult: {_value_1: ANY}
            UpdateListItemsWithKnowledge(listName: xsd:string, updates: {_value_1: ANY}, syncScope: xsd:string, knowledge: {_value_1: ANY}) -> UpdateListItemsWithKnowledgeResult: {_value_1: ANY}

     Port: ListsSoap12 (Soap12Binding: {http://schemas.microsoft.com/sharepoint/soap/}ListsSoap12)
         Operations:
            AddAttachment(listName: xsd:string, listItemID: xsd:string, fileName: xsd:string, attachment: xsd:base64Binary) -> AddAttachmentResult: xsd:string
            AddDiscussionBoardItem(listName: xsd:string, message: xsd:base64Binary) -> AddDiscussionBoardItemResult: {_value_1: ANY}
            AddList(listName: xsd:string, description: xsd:string, templateID: xsd:int) -> AddListResult: {_value_1: ANY}
            AddListFromFeature(listName: xsd:string, description: xsd:string, featureID: ns1:guid, templateID: xsd:int) -> AddListFromFeatureResult: {_value_1: ANY}
            AddWikiPage(strListName: xsd:string, listRelPageUrl: xsd:string, wikiContent: xsd:string) -> AddWikiPageResult: {_value_1: ANY}
            ApplyContentTypeToList(webUrl: xsd:string, contentTypeId: xsd:string, listName: xsd:string) -> ApplyContentTypeToListResult: {_value_1: ANY}
            CheckInFile(pageUrl: xsd:string, comment: xsd:string, CheckinType: xsd:string) -> CheckInFileResult: xsd:boolean
            CheckOutFile(pageUrl: xsd:string, checkoutToLocal: xsd:string, lastmodified: xsd:string) -> CheckOutFileResult: xsd:boolean
            CreateContentType(listName: xsd:string, displayName: xsd:string, parentType: xsd:string, fields: {_value_1: ANY}, contentTypeProperties: {_value_1: ANY}, addToView: xsd:string) -> CreateContentTypeResult: xsd:string
            DeleteAttachment(listName: xsd:string, listItemID: xsd:string, url: xsd:string) -> 
            DeleteContentType(listName: xsd:string, contentTypeId: xsd:string) -> DeleteContentTypeResult: {_value_1: ANY}
            DeleteContentTypeXmlDocument(listName: xsd:string, contentTypeId: xsd:string, documentUri: xsd:string) -> DeleteContentTypeXmlDocumentResult: {_value_1: ANY}
            DeleteList(listName: xsd:string) -> 
            GetAttachmentCollection(listName: xsd:string, listItemID: xsd:string) -> GetAttachmentCollectionResult: {_value_1: ANY}
            GetList(listName: xsd:string) -> GetListResult: {_value_1: ANY}
            GetListAndView(listName: xsd:string, viewName: xsd:string) -> GetListAndViewResult: {_value_1: ANY}
            GetListCollection() -> GetListCollectionResult: {_value_1: ANY}
            GetListContentType(listName: xsd:string, contentTypeId: xsd:string) -> GetListContentTypeResult: {_value_1: ANY}
            GetListContentTypes(listName: xsd:string, contentTypeId: xsd:string) -> GetListContentTypesResult: {_value_1: ANY}
            GetListContentTypesAndProperties(listName: xsd:string, contentTypeId: xsd:string, propertyPrefix: xsd:string, includeWebProperties: xsd:boolean) -> GetListContentTypesAndPropertiesResult: {_value_1: ANY}
            GetListItemChanges(listName: xsd:string, viewFields: {_value_1: ANY}, since: xsd:string, contains: {_value_1: ANY}) -> GetListItemChangesResult: {_value_1: ANY}
            GetListItemChangesSinceToken(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, changeToken: xsd:string, contains: {_value_1: ANY}) -> GetListItemChangesSinceTokenResult: {_value_1: ANY}
            GetListItemChangesWithKnowledge(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, syncScope: xsd:string, knowledge: {_value_1: ANY}, contains: {_value_1: ANY}) -> GetListItemChangesWithKnowledgeResult: {_value_1: ANY}
            GetListItems(listName: xsd:string, viewName: xsd:string, query: {_value_1: ANY}, viewFields: {_value_1: ANY}, rowLimit: xsd:string, queryOptions: {_value_1: ANY}, webID: xsd:string) -> GetListItemsResult: {_value_1: ANY}
            GetVersionCollection(strlistID: xsd:string, strlistItemID: xsd:string, strFieldName: xsd:string) -> GetVersionCollectionResult: {_value_1: ANY}
            UndoCheckOut(pageUrl: xsd:string) -> UndoCheckOutResult: xsd:boolean
            UpdateContentType(listName: xsd:string, contentTypeId: xsd:string, contentTypeProperties: {_value_1: ANY}, newFields: {_value_1: ANY}, updateFields: {_value_1: ANY}, deleteFields: {_value_1: ANY}, addToView: xsd:string) -> UpdateContentTypeResult: {_value_1: ANY}
            UpdateContentTypeXmlDocument(listName: xsd:string, contentTypeId: xsd:string, newDocument: {_value_1: ANY}) -> UpdateContentTypeXmlDocumentResult: {_value_1: ANY}
            UpdateContentTypesXmlDocument(listName: xsd:string, newDocument: {_value_1: ANY}) -> UpdateContentTypesXmlDocumentResult: {_value_1: ANY}
            UpdateList(listName: xsd:string, listProperties: {_value_1: ANY}, newFields: {_value_1: ANY}, updateFields: {_value_1: ANY}, deleteFields: {_value_1: ANY}, listVersion: xsd:string) -> UpdateListResult: {_value_1: ANY}
            UpdateListItems(listName: xsd:string, updates: {_value_1: ANY}) -> UpdateListItemsResult: {_value_1: ANY}
            UpdateListItemsWithKnowledge(listName: xsd:string, updates: {_value_1: ANY}, syncScope: xsd:string, knowledge: {_value_1: ANY}) -> UpdateListItemsWithKnowledgeResult: {_value_1: ANY}

我的第二个问题,从这个转储中,我将如何使用输入调用函数。说GetVersionCollection

编辑:

使用dir(result),我看到结果的属性是:

['__class__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__deli
tem__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__',
'__init__', '__iter__', '__len__', '__new__', '__nonzero__', '__reduce__', '__re
duce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof_
_', '__str__', '__subclasshook__', '_init', 'addnext', 'addprevious', 'append',
'attrib', 'base', 'clear', 'cssselect', 'extend', 'find', 'findall', 'findtext',
 'get', 'getchildren', 'getiterator', 'getnext', 'getparent', 'getprevious', 'ge
troottree', 'index', 'insert', 'items', 'iter', 'iterancestors', 'iterchildren',
 'iterdescendants', 'iterfind', 'itersiblings', 'itertext', 'keys', 'makeelement
', 'nsmap', 'prefix', 'remove', 'replace', 'set', 'sourceline', 'tag', 'tail', '
text', 'values', 'xpath']

,从type(result)开始,对象类型为lxml.etree._Element.,所以我离回答第一个问题有点近了。

编辑2: 使用etree.tostring(result)我能够看到完整的xml ...并且查看lxml.etree文档,我可以看到它遵循迭代器模式,所以我现在有了有关如何解析此消息的信息(尽管它将痛苦)。到达那里...

0 个答案:

没有答案