BingAds / BingAds-Python-SDK

Other
116 stars 162 forks source link

Allow alternatives to default suds file cache #4

Closed kil closed 7 years ago

kil commented 9 years ago

The suds client instantiated at https://github.com/bing-ads-sdk/BingAds-Python-SDK/blob/master/bingads/service_client.py#L250-L252 uses the default suds caching strategy and file location (thats /tmp/suds, where the /tmp part comes from gettempdir()).

That means if two users run this test program:

from bingads import ServiceClient
#EOF

the one that comes second will see this error:

Traceback (most recent call last):
  File "bin/python", line 146, in <module>
    exec(compile(__file__f.read(), __file__, "exec"))
  File "a.py", line 1, in <module>
    from bingads import ServiceClient
  File "/x/eggs/bingads-9.3.2-py2.7.egg/bingads/__init__.py", line 3, in <module>
    from .service_client import *
  File "/x/eggs/bingads-9.3.2-py2.7.egg/bingads/service_client.py", line 251, in <module>
    'file:///' + pkg_resources.resource_filename('bingads', 'proxies/campaign_management_service.xml')
  File "/x/eggs/suds_jurko-0.6-py2.7.egg/suds/client.py", line 112, in __init__
    kwargs["cache"] = ObjectCache(days=1)
  File "/x/eggs/suds_jurko-0.6-py2.7.egg/suds/cache.py", line 119, in __init__
    self.checkversion()
  File "/x/eggs/suds_jurko-0.6-py2.7.egg/suds/cache.py", line 242, in checkversion
    self.clear()
  File "/x/eggs/suds_jurko-0.6-py2.7.egg/suds/cache.py", line 211, in clear
    for fn in os.listdir(self.location):
OSError: [Errno 13] Permission denied: '/tmp/suds'

Would be great if that was configurable (eg. if it was possible to provide the cache argument to the suds client).

freiz commented 9 years ago

Thanks for reporting this!

This is basically a design flaw of suds-jurko (0.6.0), the development branch of suds-jurko 0.7.0 has fixed this problem, you can read the change log here https://bitbucket.org/jurko/suds, before the suds-jurko 0.7.0 release, We can first take a work around for this problem, and give a solution for this problem in the next release of bingads.

kil commented 9 years ago

Thank you for looking into this, i would really appreciate it if you guys could provide a work around until when or if there is an update to suds-jurko.

imagineful commented 7 years ago

currently no plan to fix it. close issue. Thanks.

duijf commented 6 years ago

This is causing issues on our production systems. We spawn a reasonable amount of processes that require this library and the amount of stuff that is being written to disk just by importing ServiceClient is ridiculous, especially as there is no easy way to disable this behavior.

Please reconsider fixing this.

Ugly workaround for people getting to this issue (only use if you never require any caching)

import suds.cache

class UglyNoCache(suds.cache.NoCache):
    def __init__(self, location=None, **duration):
        print("Ugly hack to monkeypatch bing ads's import defaults")

suds.cache.ObjectCache = UglyNoCache
EamonnONeill commented 6 years ago

Thanks @duijf !