在Python中使用Pingar API。服务器引发Webfault:对象引用未设置为对象的实例

时间:2014-01-09 23:30:21

标签: python api wsdl

大家晚上好。 我想提一下,关于wsdl,肥皂,泡沫,我对这件事情都很新!试着提供尽可能多的信息。 wsdl就是这个http://api3.pingar.com/PingarAPIService.asmx?WSDL

我花了好几个小时试图找到我正在使用的代码有什么问题,但最终却没有结果。我借用了这里找到的代码:https://gist.github.com/maheshcr/1829570,并填写了必要的字段(AppID,KeyID)。 我的问题是,当我运行此代码时,我收到: 服务器引发的错误:'服务器无法处理请求。 --->对象引用未设置为对象的实例。'

当我在网上看到类似的问题时,我认为它必须是一个印刷错误。在仔细检查并比较wsdl和代码调用之后,我没有发现任何错误。

我真的没有想法,作为最后的手段,我在这里寻求帮助。 以下是在我的命令行上打印的请求正文:

(PingarAPIRequest){
   AppID = "12345abc" #hypothetical appid
   AppKey = "abcd123456" #hypothetical appkey
   Language = "en"
   RapidDiscovery = 
      (RapidDiscovery){
         Query = None
         Documents = 
            (Documents){
               string[] = <empty>
            }
         DocumentsFormat = <empty>
         NumberOfResults = None
         SummaryLength = None
         MinKeyphraseness = None
      }
   EntityExtraction = 
      (EntityExtractionRequest){
         Documents = 
            (ArrayOfString){
               string[] = 
                  "Just a random input where we expect to find iron man 3 and the hobbit as the extracted entities.
",
            }
         DocumentsFormat = "Text"
         IncludeSingleSiblings = True
         TaxonomyNames = 
            (TaxonomyNames){
               string[] = <empty>
            }
         NumberOfKeywords = 10
         EntitiesToExtract = 
            (EntitiesToExtract){
               EntityTypes[] = <empty>
            }
         WikifyLinkDensity = 0.5
      }
   ContentAnalysis = 
      (ContentAnalysis){
         Documents = 
            (Documents){
               string[] = <empty>
            }
         DocumentsFormat = <empty>
         SummaryLength = None
         EntitiesToRedact = 
            (EntitiesToRedact){
               EntityTypes[] = <empty>
            }
         EntitiesToSanitize = 
            (EntitiesToSanitize){
               EntityTypes[] = <empty>
            }
      }
 }

任何帮助和/或建议都将受到高度赞赏! 在此先感谢您的时间,我将确保发布任何更多信息尽快。我希望这篇文章能够帮助其他人。

编辑:我认为添加suds.logging信息会很有用。 调试模式 - suds.client:

DEBUG:suds.client:sending to (http://api3.pingar.com/PingarAPIService.asmx)
message:
<SOAP-ENV:Envelope xmlns:ns0="http://api.pingar.com/" xmlns:SOAP-             ENC="http://schemas.xmlsoap.org/soap/encoding/"             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-    ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns0:GetEntities>
         <ns0:request>
            <ns0:AppID>hypothetical appID</ns0:AppID>
            <ns0:AppKey>hypothetical appKey</ns0:AppKey>
            <ns0:Language xsi:type="ns0:LanguageCodes">en</ns0:Language>
            <ns0:EntityExtraction>
               <ns0:Documents>
                  <ns0:string>Just a random input where we expect to find iron man 3     and the hobbit as the extracted entities.
</ns0:string>
               </ns0:Documents>
               <ns0:DocumentsFormat     xsi:type="ns0:DocumentFormat">Text</ns0:DocumentsFormat>
               <ns0:IncludeSingleSiblings>true</ns0:IncludeSingleSiblings>
               <ns0:NumberOfKeywords>50</ns0:NumberOfKeywords>
               <ns0:WikifyLinkDensity>0.5</ns0:WikifyLinkDensity>
            </ns0:EntityExtraction>
         </ns0:request>
      </ns0:GetEntities>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': u'"http://api(dot)pingar.com/GetEntities"',     'Content-Type': 'text/xml'}
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://api(dot)pingar.com/" xmlns:SOAP-    ENC="http://schemas(dot)xmlsoap.org/soap/encoding/"     xmlns:xsi="http://www(dot)w3.org/2001/XMLSchema-instance" xmlns:SOAP-    ENV="http://schemas(dot)xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns0:GetEntities>
         <ns0:request>
            <ns0:AppID>hypothetical appid</ns0:AppID>
            <ns0:AppKey>hypothetical appkey</ns0:AppKey>
            <ns0:Language xsi:type="ns0:LanguageCodes">en</ns0:Language>
            <ns0:EntityExtraction>
               <ns0:Documents>
                  <ns0:string>Just a random input where we expect to find iron man 3     and the hobbit as the extracted entities.
</ns0:string>
               </ns0:Documents>
               <ns0:DocumentsFormat     xsi:type="ns0:DocumentFormat">Text</ns0:DocumentsFormat>
               <ns0:IncludeSingleSiblings>true</ns0:IncludeSingleSiblings>
               <ns0:NumberOfKeywords>50</ns0:NumberOfKeywords>
               <ns0:WikifyLinkDensity>0.5</ns0:WikifyLinkDensity>
            </ns0:EntityExtraction>
         </ns0:request>
      </ns0:GetEntities>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:http failed:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault>    <faultcode>soap:Server</faultcode><faultstring>Server was unable to process request. ---    &gt; Object reference not set to an instance of an object.</faultstring><detail />    </soap:Fault></soap:Body></soap:Envelope>
Server raised fault: 'Server was unable to process request. ---> Object reference     not set to an instance of an object.'

1 个答案:

答案 0 :(得分:0)

<SOAP-ENV:Envelope xmlns:ns0="http://api.pingar.com/" xmlns:SOAP-             ENC="http://schemas.xmlsoap.org/soap/encoding/"             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-    ENV="http://schemas.xmlsoap.org/soap/envelope/">

纠正上述行。删除请求soap-ENV中的空格,如SOAP-ENC和SOAP-ENV之间的空格,您将得到您的响应。我尝试使用soapui,我得到了回复。

我通过删除空格尝试了以下请求。

<SOAP-ENV:Envelope xmlns:ns0="http://api.pingar.com/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
  <ns0:GetEntities>
     <ns0:request>
        <ns0:AppID>hypothetical appID</ns0:AppID>
        <ns0:AppKey>hypothetical appKey</ns0:AppKey>
        <ns0:Language xsi:type="ns0:LanguageCodes">en</ns0:Language>
        <ns0:EntityExtraction>
           <ns0:Documents>
              <ns0:string>Just a random input where we expect to find iron man 3      and the hobbit as the extracted entities.
    </ns0:string>
           </ns0:Documents>
           <ns0:DocumentsFormat      xsi:type="ns0:DocumentFormat">Text</ns0:DocumentsFormat>
           <ns0:IncludeSingleSiblings>true</ns0:IncludeSingleSiblings>
           <ns0:NumberOfKeywords>50</ns0:NumberOfKeywords>
           <ns0:WikifyLinkDensity>0.5</ns0:WikifyLinkDensity>
        </ns0:EntityExtraction>
     </ns0:request>
    </ns0:GetEntities>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>