IbPy 无法通过 IB 网关连接到 TWS

IbPy can't connect to TWS through IB Gateway

我正在使用 IB 网关连接到 tws,IbPy 示例 Python 来自 https://gist.github.com/valiant-falstaff/4093998b625d76ef4afe 的 2.7 代码产生以下错误:

Server Error: <error id=-1, errorCode=502, errorMsg=Couldn't connect to TWS.  
Confirm that "Enable ActiveX and Socket Clients" is enabled on the TWS 
"Configure->API" menu.>
Server Response: error, <error id=-1, errorCode=502, errorMsg=Couldn't 
connect to TWS.  Confirm that "Enable ActiveX and Socket Clients" is enabled 
on the TWS "Configure->API" menu.>
Server Error: <error id=-1, errorCode=504, errorMsg=Not connected>
Server Response: error, <error id=-1, errorCode=504, errorMsg=Not connected>

但是,我没有在我找到的所有示例中显示的网关 GUI 中选择 select "Enable ActiveX and Socket Clients"。这就是 "standard" 设置 window 的样子。 and this is what my settings window looks like 。有人知道我该如何解决这个问题吗?

Brian 发现了问题 - 代码调用了与 GUI 屏幕截图不同的端口。 (为了结束而回答)