类型错误:<lambda>() 采用 1 个位置参数,但在 simplefix get 方法中给出了 2 个

问题描述

我使用的是 simplefix (https://github.com/da4089/simplefix) 版本 1.0.14。出于某种原因,我似乎从库中使用了过时的方法。这是错误信息:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py",line 954,in _bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py",line 892,in run
    self._target(*self._args,**self._kwargs)
  File "/Users/recapital/Git/tt-fix/client.py",line 59,in run
    self._reader.on_message(msg)
  File "/Users/recapital/Git/tt-fix/message_handler.py",line 31,in on_message
    self.handle_logon(message)
  File "/Users/recapital/Git/tt-fix/message_handler.py",line 39,in handle_logon
    logon.decode(message)
  File "/Users/recapital/Git/tt-fix/tt_messages.py",line 9517,in decode
    if (val := message.get(FIELD_ENCRYPT_METHOD,nth)) is not None:
TypeError: <lambda>() takes 1 positional argument but 2 were given

这是调用代码

def decode(self,message: FixMessage,nth: int = 1):
    if (val := message.get(FIELD_ENCRYPT_METHOD,nth)) is not None:
        self.encrypt_method = EncryptMethod(int(val))

这里是 simplefix 中的 get 方法

def get(self,tag,nth=1):
    """Return n-th value for tag.

    :param tag: FIX field tag number.
    :param nth: Index of tag if repeating,first is 1.
    :return: None if nothing found,otherwise value matching tag.

    Defaults to returning the first matching value of 'tag',but if
    the 'nth' parameter is overridden,can get repeated fields."""

    tag = fix_tag(tag)
    nth = int(nth)

    for t,v in self.pairs:
        if t == tag:
            nth -= 1
            if nth == 0:
                return v

    return None

如果我不传递第 n 个参数,它会起作用,但是提供这个(由于重复,我必须这样做)会产生这个奇怪的错误

编辑:2021.06.23 11:44 CET

我通过将消息提取到它自己的方法来让它工作:

def get_field(message: FixMessage,nth=1):
tag = fix_tag(tag)
nth = int(nth)
for t,v in message.pairs:
    if t == tag:
        nth -= 1
        if nth == 0:
            return v
return None

不确定为什么相同的代码一个地方有效,而在另一个地方无效。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...