【问题标题】:Error while calling function in Python3.5在 Python3.5 中调用函数时出错
【发布时间】:2018-06-26 09:55:27
【问题描述】:

我正在尝试运行IqoptionAppi的存储库

当我尝试运行命令时:api.getcandles(1,60,25)
出现以下错误:

api.getcandles(1,60,25)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __call__() takes 3 positional arguments but 4 were given

我看过这个函数,是这样的:

from iqoptionapi.ws.chanels.base import Base


class GetCandles(Base):
    """Class for IQ option candles websocket chanel."""
    # pylint: disable=too-few-public-methods

    name = "candles"

    def __call__(self, active_id, duration, amount):
        """Method to send message to candles websocket chanel.

        :param active_id: The active/asset identifier.
        :param duration: The candle duration (timeframe for the candles).
        :param amount: The number of candles you want to have
        """
        data = {"active_id": active_id,
                "duration": duration,
                "chunk_size": 25,
                "from": self.api.timesync.server_timestamp - (duration * amount),
                "till": self.api.timesync.server_timestamp}

        self.send_websocket_request(self.name, data)

存储库说它可以在Python 2.7 上运行,但我尝试在Python 3.5 上安装它,除了上述问题外它仍然有效。引导我到我错过的地方。

【问题讨论】:

  • 我相信您将 self 作为第一个参数。当调用一个类的成员方法时,python会为你做。
  • @Sianur 但是我在调​​用函数时没有使用它,您可以在我的示例中看到它。
  • 发布您创建 api 对象的行
  • @miindlek 好的,看到这个:api = IQOptionAPI("iqoption.com", "name@email.com", "Passwordhidden"),这就是我创建对象的方式。
  • 好吧,我本地安装了,只有2个参数(self除外):active_idduration

标签: python python-3.x python-2.x


【解决方案1】:

这里的问题是latest PyPI version中的iqoptionapi/ws/chanels/candles.py模块与Github's master branch version不同,并且没有amount参数(它似乎等于2)。

master 分支:

def __call__(self, active_id, duration, amount):
    ...
    "from": self.api.timesync.server_timestamp - (duration * amount),
    ...

0.5 版本中:

def __call__(self, active_id, duration):
    ...
    "from": self.api.timesync.server_timestamp - (duration * 2),
    ...

所以我们可以忽略这个参数(根本不传递,使用默认值2)或者install master branch version using git之类的

> pip install --upgrade git+https://github.com/n1nj4z33/iqoptionapi.git@master

这里我们使用--upgrade 标志,因为版本没有改变,所以我们强制重新安装包。

或者另一种选择:您可以要求 repo 所有者发布新版本并在 PyPI 上发布。

【讨论】:

  • 更新后,出现错误:TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
最近更新 更多