python 3 suds缓存不起作用

编程入门 行业动态 更新时间:2024-10-13 04:20:58
本文介绍了python 3 suds缓存不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写用于通过Python访问Sharepoint的脚本。

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

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

#!/ usr / bin / env python3 来自suds.client import客户端来自suds.transport.https import WindowsHttpAuthenticated 来自suds.cache import ObjectCache url ='http://blah/_vti_bin/Lists.asmx?WSDL'用户=等等 passwd =等等 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 2月5日13:27版本- rw-r--r-- 1 pchernik smsvcs 309572 2月5日13:27 suds-536283349122900148-document.px -rw-r--r-- 1 pchernik smsvcs 207647 2月5日13:27 suds-4765026134651708722- document.px -rw-r--r-- 1 pchernik smsvcs 21097 2月5日13:27 suds-1421279777216033364-document.px -rw-r--r-- 1 pchernik smsvcs 207644 2月5 13:27 suds-6437332842122298485-document.px -rw-r--r-- 1 pchernik smsvcs 309572 2月5日13:27 suds-3510377615213316246-document.px -rw-r-- r-- 1个pchernik smsvcs 21097 2月5日13:28 suds-7540886319990993060-document.px -rw-r--r-- 1个pchernik smsvcs 207617 2月5日13:30 suds-1166110448227246785-document.px -rw-r--r-- 1个pchernik smsvcs 309548 2月5日13:30 suds-2848176348666425151-document.px -rw-r--r--r-- 1 pchernik smsvcs 21076 2月5日13:31 suds -6077994449274214633-document.px

  • 泡沫通常这么慢吗?
  • 任何
  • 还有其他可以用来代替suds的python 3库吗?

任何想法/建议都会受到赞赏。

谢谢, -Pavel

解决方案

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

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

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

来自suds文档:

缓存策略

缓存策略确定如何缓存数据。默认值为0。版本0.4 +

  • 0 = XML文档,例如WSDL& XSD。
  • 1 = WSDL对象图。

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

如果未指定缓存位置,则临时默认位置为已使用。这样的默认缓存位置将由所有FileCache 实例共享,而在同一进程中没有明确指定的位置。 除非用户将remove_default_location_on_exit FileCache类属性设置为False,否则进程退出时将自动删除默认缓存位置。

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

#配置缓存位置和持续时间('days = 0'=无限) 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属性,但是我没有尝试过这种方法。 / p>

I'm trying to write a script for accessing Sharepoint via Python.

The following libraries have been installed: suds.jurko, ntlm.

The following code succeeds, but takes close to 20 seconds:

#!/usr/bin/env python3 from suds.client import Client from suds.transport.https import WindowsHttpAuthenticated from suds.cache import ObjectCache url = 'blah/_vti_bin/Lists.asmx?WSDL' user = "blah" passwd = "blah" ntlm = WindowsHttpAuthenticated(username=user, password=passwd) client = Client(url, transport=ntlm)

I tried adding cache:

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

I see /tmp/suds created and I see cached files under there, but it looks like it just creates more files on every run, instead of using the cached files:

-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

  • Is suds normally this slow?
  • Any ideas on fixing the caching issues?
  • Are there any other python 3 libraries I can use for this instead of suds?

Any ideas / suggestions are appreciated.

Thanks, -Pavel

解决方案

I had the same issue, try setting your cachingpolicy to 1:

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

This will cache your WSDL objects instead of your XML files.

From suds documentation:

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.

Edit: I re-read your question and realized I am missing something important; your cache is getting re-generated. I believe this is due to not specifying a location for the cache. This is from the documentation of the FileCache class in cache.py:

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.

So, even if you want to use the default cache location, you will need to explicitly define it when you create your cache object. This is what I've done in my code:

# 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)

You could also try setting the remove_default_location_on_exit attribute as suggested in the FileCache documentation, but I have not tried this method.

更多推荐

python 3 suds缓存不起作用

本文发布于:2023-11-26 08:39:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   不起作用   python   suds

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!