群益API: m_nCode回報錯誤代碼2017之處理
class MyMainWindow(QMainWindow, Ui_Form):
def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.twTest) #ctw signal
def twTest(self): #ctw slot function
print("test...")
self.listWidget.addItem("add item")
twLogin("ID: xxxxxx", "PW: xxxxxxxxx")
global GlobalListInformation,Global_ID
GlobalListInformation = self.listWidget
#Global_ID = self.labelID
發生m_nCode回報2017錯誤(正常連線時, m_nCode回報0)
def twLogin(twID, twPW):
try:
m_nCode = skC.SKCenterLib_SetLogPath(os.path.split(os.path.realpath(__file__))[0] + "\\CapitalLog_Quote")
m_nCode = skC.SKCenterLib_Login(twID, twPW)
if(m_nCode==0):
Global_ID["text"] = twID # textID: ID帳號
SetID(twID) #ctw focus
print("登入成功")
WriteMessage("登入成功",GlobalListInformation)
else:
WriteMessage(m_nCode,GlobalListInformation)
except Exception as e:
messagebox.showerror("error!",e)
因此, 在程式上方加上以下程式碼後, 2017錯誤終於順利解決了.. (sConfirmCode不能用-1, 要用0xFFFF才行)
class SKReplyLibEvent():
def OnReplyMessage(self,bstrUserID, bstrMessages):
#根據API 手冊,login 前會先檢查這個 callback,
#要返回 VARIANT_TRUE 給 server, 表示看過公告了,我預設返回值是 0xFFFF
#sConfirmCode = -1 # 會出現2017錯誤
sConfirmCode = 0xFFFF # 改後就一切正常了..
print('OnReplyMessage 回報正常', bstrMessages) #ctw
#WriteMessage(bstrMessages,GlobalListInformation)
return sConfirmCode
# comtypes使用此方式註冊callback
SKReplyEvent = SKReplyLibEvent()
SKReplyLibEventHandler = comtypes.client.GetEvents(skR, SKReplyEvent)
而是後面的WriteMessage()出錯, 才造成OnReplyMessage沒法正常回報,
進而導致2017錯誤..
.
所以, 只要把WriteMessage()註解掉, 問題就解決了..
class SKReplyLibEvent():
def OnReplyMessage(self,bstrUserID, bstrMessages):
#根據API 手冊,login 前會先檢查這個 callback,
#要返回 VARIANT_TRUE 給 server, 表示看過公告了,我預設返回值是 0xFFFF
sConfirmCode = -1 # 會出現2017錯誤
#sConfirmCode = 0xFFFF # 改後就一切正常了..
print('OnReplyMessage 回報正常', bstrMessages) #ctw
#WriteMessage(bstrMessages,GlobalListInformation)
return sConfirmCode
沒有留言:
張貼留言