xlwings error: pywintypes.com_error: (-2147352573, 'Member not found.', None, None)

北城余情 提交于 2021-02-19 08:09:05

问题


I have an Excel open which has RTD streaming data (financial data from a trading platform). My goal is read the data by Python and save it as soon as it changes. The goal is to capture every milisecond. I am using xlwings to read the cell value but usually after 50-100 attempts I got the same error. Any idea how to solve it?

import xlwings as xw

n_of_times_checked=0
while True:
    n_of_times_checked +=1
    print("Cell value:",xw.Range("D41").value," Num of times checked:",n_of_times_checked)

The result:

Cell value: 55.0  Num of times checked: 71
Cell value: 55.0  Num of times checked: 72
Cell value: 55.0  Num of times checked: 73
Cell value: 55.0  Num of times checked: 74
Cell value: 55.0  Num of times checked: 75
Traceback (most recent call last):
  File "D:/Google drive/Python/Backtesting/backtesting_uj/RTD_recorder.py", line 7, in <module>
    print("Cell value:",xw.Range("D41").value," Num of times checked:",n_of_times_checked)
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\main.py", line 999, in __init__
    impl = apps.active.range(cell1).impl
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\main.py", line 392, in range
    return Range(impl=self.impl.range(cell1, cell2))
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\_xlwindows.py", line 401, in range
    xl1 = self.xl.Range(arg1)
  File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\_xlwindows.py", line 63, in __call__
    v = self.__method(*args, **kwargs)
  File "<COMObject <unknown>>", line 2, in Range
pywintypes.com_error: (-2147352573, 'Member not found..', None, None)

回答1:


I was looking for help since I do not get, as you a value, I just get #¿NAME? with my code although keying F2 F9 get the right value (rtd.tos). Anyhow, I guess the problem is your code crashes when looking for a value while it is changing/refreshing, so I would suggest using try/except wrapping your print statement. Also, beware that rtd in refreshing rate according to Application.RTD.ThrottleInterval value (default 1 second).



来源:https://stackoverflow.com/questions/55422990/xlwings-error-pywintypes-com-error-2147352573-member-not-found-none-no

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!