caching - python 3 suds 缓存不工作

标签 caching sharepoint python-3.x soap suds

我正在尝试编写一个脚本来通过 Python 访问 Sharepoint。

已安装以下库:suds.jurko、ntlm。

以下代码成功,但需要接近 20 秒:

#!/usr/bin/env python3

from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
from suds.cache import ObjectCache

url = 'http://blah/_vti_bin/Lists.asmx?WSDL'
user = "blah"
passwd = "blah"

ntlm = WindowsHttpAuthenticated(username=user, password=passwd)
client = Client(url, transport=ntlm)

我尝试添加缓存:

oc = ObjectCache()
oc.setduration(days=10)
client = Client(url, transport=ntlm, cache=oc)

我看到/tmp/suds 已创建,并且在下面看到了缓存文件,但看起来它只是在每次运行时创建更多文件,而不是使用缓存文件:

-rw-r--r-- 1 pchernik smsvcs      3 Feb  5 13:27 version
-rw-r--r-- 1 pchernik smsvcs 309572 Feb  5 13:27 suds-536283349122900148-document.px
-rw-r--r-- 1 pchernik smsvcs 207647 Feb  5 13:27 suds-4765026134651708722-document.px
-rw-r--r-- 1 pchernik smsvcs  21097 Feb  5 13:27 suds-1421279777216033364-document.px
-rw-r--r-- 1 pchernik smsvcs 207644 Feb  5 13:27 suds-6437332842122298485-document.px
-rw-r--r-- 1 pchernik smsvcs 309572 Feb  5 13:27 suds-3510377615213316246-document.px
-rw-r--r-- 1 pchernik smsvcs  21097 Feb  5 13:28 suds-7540886319990993060-document.px
-rw-r--r-- 1 pchernik smsvcs 207617 Feb  5 13:30 suds-1166110448227246785-document.px
-rw-r--r-- 1 pchernik smsvcs 309548 Feb  5 13:30 suds-2848176348666425151-document.px
-rw-r--r-- 1 pchernik smsvcs  21076 Feb  5 13:31 suds-6077994449274214633-document.px
  • 泡沫通常这么慢吗?
  • 对于解决缓存问题有什么想法吗?
  • 除了 suds 之外,我还可以使用其他 python 3 库吗?

如有任何想法/建议,我们将不胜感激。

谢谢, -帕维尔

最佳答案

我遇到了同样的问题,请尝试将缓存策略设置为 1:

client = Client(url, transport=ntlm, cache=oc, cachingpolicy=1)

这将缓存您的 WSDL 对象而不是 XML 文件。

来自泡沫文档:

cachingpolicy

The caching policy, determines how data is cached. The default is 0. version 0.4+

  • 0 = XML documents such as WSDL & XSD.
  • 1 = WSDL object graph.

编辑:我重新阅读了你的问题,意识到我遗漏了一些重要的东西;您的缓存正在重新生成。我认为这是由于没有指定缓存位置造成的。这是来自cache.py中FileCache类的文档:

If no cache location is specified, a temporary default location will be used. Such default cache location will be shared by all FileCache instances with no explicitly specified location within the same process. The default cache location will be removed automatically on process exit unless user sets the remove_default_location_on_exit FileCache class attribute to False.

因此,即使您想使用默认缓存位置,您也需要在创建缓存对象时显式定义它。这就是我在代码中所做的:

    # Configure cache location and duration ('days=0' = infinite)
    cache_dir = os.path.join(os.path.abspath(os.sep), r'tmp\suds')
    self.cache = ObjectCache(cache_dir, days=0)

您还可以尝试按照 FileCache 文档中的建议设置remove_default_location_on_exit 属性,但我还没有尝试过此方法。

关于caching - python 3 suds 缓存不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28351699/

相关文章:

python - Catboost 的 verbose 可以是 int 吗?

java - 如何制作一个理想的缓存?

javascript - 带有 SPServices + jQuery 的 CORS

Angularjs $http缓存刷新

javascript - 无法将 JQuery Datepicker 与 asp 绑定(bind) :TextBox in sharepoint

c# - 多用户环境中的静态变量与公共(public)变量

Python-将特定文件从列表复制到新文件夹中

python - 如何使用 python 向当前终端历史记录添加命令?

caching - 经典asp中应用程序对象的大小限制是多少?

java - Hibernate 不会注意到来自其他来源的数据库更新