查询桌面搜索时如何使用win32com处理溢出? [英] How to use win32com to handle overflow when querying Desktop Search?

查看:107
本文介绍了查询桌面搜索时如何使用win32com处理溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python + ADO查询Windows桌面搜索JET(ESE)数据库。它可以工作,但是在〜7600条记录之后,使用 MoveNext 前进到下一条记录时出现异常。我知道它不在EOF上,因为我可以在VBScript中运行相同的查询,并通过相同的查询获取更多记录。

I'm querying the Windows Desktop Search JET (ESE) database using Python + ADO. It works but after ~7600 records I get an exception when advancing to the next record using MoveNext. I know it is not at EOF because I can run the same query in VBScript and get way more records with the same query.

Traceback (most recent call last):
  File "test_desktop_search.py", line 60, in <module>
    record_set.MoveNext()
  File "<COMObject ADODB.Recordset>", line 2, in MoveNext
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147215865), None)

查询该错误,表明该错误:


  • 常数: adErrDataOverflow

  • 值: 3721 -2146824567 0x800A0E89

  • 说明:数据值太大,无法用字段数据类型表示。

  • Constant: adErrDataOverflow
  • Value: 3721 -2146824567 0x800A0E89
  • Description: Data value is too large to be represented by the field data type.

这在VBScript中可以正常工作(但可能仅是由于错误处理不佳)。 PowerShell有以下错误(在超越Python之后,与VBScript差不多):

This works fine in VBScript (but perhaps only due to poor error handling). PowerShell has the following error (after getting much further than Python, about to the same place as VBScript gets):

Exception from HRESULT: 0x80041607
At C:\Users\doday\PycharmProjects\desktop_search_test\Get-DesktopSearchData.ps1:43 char:5
+     $recordSet.MoveNext();
+     ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

我在Microsoft文档中找不到此错误代码,但是很可能有关。如您所见,Facility字段为4(特定于接口的HRESULT错误),代码为1607。

I could not find this error code in Microsoft documentation, but it is likely related. As you can see, the Facility field is 4 (interface-specific HRESULT error) and the code is 1607.

#!/usr/bin/env python
"""
Test querying Desktop Search from Python
"""

import csv
import pywintypes
from win32com.client import Dispatch

# connection
conn = Dispatch("ADODB.Connection")
connstr = "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
conn.Open(connstr)

# record set
record_set = Dispatch("ADODB.Recordset")
q = "SELECT System.ItemName, System.ItemTypeText, System.Size, System.IsDeleted, System.DateAccessed, System.Kind, System.ItemDate, System.Search.Store, System.ItemParticipants, System.ItemAuthors, System.IsRead, System.Message.AttachmentNames FROM SystemIndex"
# record_set.ActiveConnection = conn
record_set.Open(q, conn)

# header
# I'm only selecting a few fields for this test, see
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb419046(v=vs.85).aspx
header = [
    "System.ItemName",
    "System.ItemTypeText",
    "System.Size",
    "System.IsDeleted",
    "System.DateAccessed",
    "System.Kind",
    "System.ItemDate",
    "System.Search.Store",
    "System.ItemParticipants",
    "System.ItemAuthors",
    "System.IsRead",
    "System.Message.AttachmentNames"
]

# output to file
with open("ds_output.tsv", "w", newline='') as out_f:
    w = csv.DictWriter(out_f, fieldnames=header, delimiter='\t')
    w.writeheader()
    record_set.MoveFirst()
    while not record_set.EOF:
        record = dict.fromkeys(header)

        # populate fields
        for h in header:
            record[h] = record_set.Fields.Item(h).Value

        # write record
        w.writerow(record)

        try:
            record_set.MoveNext()
        except pywintypes.com_error as e:
            # can't figure out how to resolve this or at least advance to next record despite this error
            print("Error: {}".format(e.args))

# clean up
record_set.Close()
record_set = None
conn.Close()
conn = None



我是什么到目前为止,已经尝试过




  • 我尝试删除了 System.Message.AttachmentNames 我查询中的列/字段,但实际上使它更快地失败了/出现了相同错误的记录减少了(在 args 例外中的第一个数字是相同)。

  • 我只尝试使用一个字段( System.ItemName ),这使其两倍于其他尝试在Python中使用,但最终由于UnicodeEncodeError失败(这似乎与上面显示的其他错误无关,这阻止了它再次使用该错误生成文件名)。

  • 我尝试使用PowerShell,还收到了 COMException (上面显示了错误输出)。

  • What I've tried so far

    • I tried removing the "System.Message.AttachmentNames" column/field from my query but that actually made it fail faster / after fewer records with what appears to be the same error (the first number in the exception args is the same).
    • I tried only using one field ("System.ItemName"), which made it twice as far as other attempts in Python but ended up failing on a UnicodeEncodeError (which does not appear to be related to the other error shown above, which prevents it from ever making it to the file name with that error).
    • I tried using PowerShell and also received a COMException (error output shown above).
    • 推荐答案

      您的引用显示为-2147352567错误代码。这是DISP_E_EXCEPTION,这是一种非常通用的COM异常。
      它包装了-2147215865错误,它也是0x80041607,也就是QUERY_E_TIMEDOUT。

      Your trackback shows a -2147352567 error code. This is DISP_E_EXCEPTION, a very generic COM exception. It wraps a -2147215865 error, which is also 0x80041607, which is also QUERY_E_TIMEDOUT.

      我使用这个免费的网站工具-我做到了-查找错误以及其他类似的常量: https://www.magnumdb.com/search?q=- 2147215865

      I use this free website tool - I made it - to find errors and other constants like that: https://www.magnumdb.com/search?q=-2147215865

      因此,实际上,它们都报告了相同的超时错误。

      So, in fact, they all report the same timeout error.

      您可以如此处所述增加ADO超时: SystemIndex出现问题(我喜欢它,但无法使其正常工作想要)

      You can increase ADO timeout as described here: Having Problems With SystemIndex (I Love It But Can't Make It Work How I Want)

      ,也可以使用以下代码将其完全删除:

      or you can remove it completely, with a code like this:

      conn.CommandTimeout = 0
      

      这篇关于查询桌面搜索时如何使用win32com处理溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆