0

リモートWebサービスからgetメソッドを実行しようとすると、エラーが発生します。

私のコードは次のとおりです。

        portion=10
        start=0
        print self.stamp.datetime
        client=self.client
        while 1:
            print 'getting ids...........'
            fresh_ids=client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) #this line makes exception
            if len(fresh_ids) is not 0:
                for id in fresh_ids:
                    yield id
                start=+portion
            else:
                print 'No updated topics anymore'
                sys.exit()

トレースバックがあります:

 /usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/client.py
in invoke(self, args, kwargs)
    469         binding = self.method.binding.input
    470         binding.options = self.options
--> 471         msg = binding.get_message(self.method, args, kwargs)
    472         timer.stop()
    473         metrics.log.debug(

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/bindings/binding.py
in get_message(self, method, args, kwargs)
     96         content = self.headercontent(method)
     97         header = self.header(content)
---> 98         content = self.bodycontent(method, args, kwargs)
     99         body = self.body(content)
    100         env = self.envelope(header, body)

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/bindings/rpc.py
in bodycontent(self, method, args, kwargs)
     61             p = self.mkparam(method, pd, value)
     62             if p is not None:
---> 63                 root.append(p)
     64             n += 1
     65         return root

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/sax/element.py
in append(self, objects)
    329                 child.parent = self
    330                 continue
--> 331             raise Exception('append %s not-valid' %
child.__class__.__name__)
    332         return self
    333

<type 'exceptions.Exception'>: append list not-valid

sudsモジュールには、例外を発生させるメソッドがあります。

def insert(self, objects, index=0):
        """
        Insert an L{Element} content at the specified index.
        @param objects: A (single|collection) of attribute(s) or element(s)
            to be added as children.
        @type objects: (L{Element}|L{Attribute})
        @param index: The position in the list of children to insert.
        @type index: int
        @return: self
        @rtype: L{Element}
        """
        objects = (objects,)
        for child in objects:
            if isinstance(child, Element):
                self.children.insert(index, child)
                child.parent = self
            else:
                raise Exception('append %s not-valid' % child.__class__.__name__)
        return self

コンソールでは、すべてが順調に進んでいます。私は立ち往生しています。

わかりました、私は実験をしようとしました:

def YieldID(self):
        portion=10
        start=0
        print self.stamp.datetime
        fresh_ids=self.client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) #This work
        while 1:
            print 'getting ids...........'
            fresh_ids=self.client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) # This raise exception
            if len(fresh_ids)!=0:
                for id in fresh_ids:
                    yield id
                start=+portion
            else:
                print 'No updated topics anymore'
                sys.exit()

動作を終了する前に、同じメソッドの呼び出しを追加します。しかし、それが私に例外を与えている間に中に入るとき。

ループの前にどのように機能し、ループ内では機能しないのですか?それが主な質問です。何が変わったの?

に変更whileしてみましたfor

4

1 に答える 1

2

編集:コードをもう一度見てみると、次の行に気づきました。

            start=+portion

に変更する必要があります

            start += portion

これにより、次の分析が不要になる可能性があります...ただし、以下で説明するように、sudsソースにまだ問題がある可能性があります。


私が尋ねる最初の質問は次のとおりです。self.clientへの呼び出しの間にオブジェクト内で何も変更されていないことを確認しYieldIDますか?

私が持っているもう1つの懸念は、例外が発生した関数の間違ったソースを投稿した可能性があることです。トレースバックは、への呼び出し中に例外が発生したことを示していますがappend、含めたコードはのためのものinsertです。insertの例外メッセージは、コピーアンドペーストエラーのために「追加」として識別しているように見えます。

そして、もっとあります。私が正しいソースの場所を特定したと仮定すると、これがの完全なソースでappendあり、行番号313で始まります。

def append(self, objects):
    """
    Append the specified child based on whether it is an
    element or an attrbuite.
    @param objects: A (single|collection) of attribute(s) or element(s)
        to be added as children.
    @type objects: (L{Element}|L{Attribute})
    @return: self
    @rtype: L{Element}
    """
    if not isinstance(objects, (list, tuple)):
        objects = (objects,)
    for child in objects:
        if isinstance(child, Element):
            self.children.append(child)
            child.parent = self
            continue
        if isinstance(child, Attribute):
            self.attributes.append(child)
            child.parent = self
            continue
        raise Exception('append %s not-valid' % child.__class__.__name__)
    return self

ここでは、トレースバックが示すように、例外は331行ではなく334行で発生します。

変更されたバージョンではなく、元のバージョンのsuds 0.3.5を使用していることを確認しますか?の元のバージョンには:appendとの興味深い違いがあるため、入力引数から常にタプルが作成されますが、これはせいぜい冗長に見えます。insertinsert

def insert(self, objects, index=0): // line 337
    # ... snip to line 348
    objects = (objects,)

オリジナルappendは条件付きでこれを行います(上記を参照):

    if not isinstance(objects, (list, tuple)):
        objects = (objects,)

次に、例外のメッセージを見てください。

:リストの追加は無効です

これは、追加しようとした子自体がリストであることを意味します。しかし、これはどうしてでしょうか?リストが入力として渡された場合は、そのリストの子を反復処理する必要があります...それ自体がリストであってはなりません。

うーん。おそらく、二重にネストされたリストがオブジェクトパラメータとして渡されていた可能性appendがあります。これは、データ構造のかなりひどい破損を示しているようです。(私の最初の質問を参照してください。)

または...

続くのはまったくの憶測であり、おそらく正しいとは言えません...そうでない限り...

または、リストへの条件付き変換が削除されたSudsの修正バージョンを、リストの反復とともに使用している可能性がありますか?それはあなたが投稿したコードと私がオンラインで見つけたソースの間の3行の違い(331対334)を説明するでしょう。使用しているソースファイルを再確認して、確実にお知らせください。

于 2010-07-19T17:22:56.670 に答える