python - 运行简单 API 示例时出现属性错误
问题描述
我正在运行一个非常简单的 API 示例:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
class IBapi(EWrapper, EClient):
def init(self):
EClient.init(self, self)
app = IBapi()
app.connect('127.0.0.1', 7497, 123)
app.run()
我得到的错误是:
Traceback(最近一次调用最后):文件“C:\Users\Gebruiker\Desktop\Python projects\IB TWS\test_app.py”,第 9 行,在 app.connect('127.0.0.1', 7497, 123) 文件中“ C:\Users\Gebruiker\Desktop\Python projects\IB TWS\ibapi\client.py",第 151 行,连接 self.decoder = decoder.Decoder(self.wrapper, self.serverVersion()) AttributeError: 'IBapi'对象没有属性“包装器”
如果我检查源文件中的代码,我会看到这一点(我删除了一些不相关的代码):
class EClient(object):
def __init__(self, wrapper):
self.wrapper = wrapper
def connect(self, host, port, clientId):
self.decoder = decoder.Decoder(self.wrapper, self.serverVersion())
__init__
如果它在类的函数上,怎么可能找不到包装器属性?我可能会错过什么?
我的另一个问题是,如果该类IBapi
接受 2 个参数 ( EWrapper
and EClient
),那么对象 app 怎么可能是IBapi
没有参数的类的实例?
只是为了澄清我从互联网上拿了这个例子。谢谢。
解决方案
推荐阅读
- squish - 如何在 squish 中加速工作空间的构建?
- android - 将个人位置添加到 Google Place 自动完成列表
- django - 无法为 saleor 框架 + python + django 更新 svg 文件
- android - Android O 中的 OnTaskRemoved
- android - Dagger 2 + MVP - 分配给多个片段的单个演示者
- apache - Apache Bench POST:是否可以从字符串或标准输入中读取,而不是从文件中读取?
- python - 存储字典项目以供以后检索的最佳方式?
- vba - 根据用户表单(VBA)中输入的值绘制水平线
- html - 响应式网站在 Firefox 响应模式下运行良好,不适用于 Chrome Mobile 或 Instagram 和 Facebook 等槽式浏览器
- android - 在 SQLite 中保存和显示图像