2

so - I'm using a library pyminizip - which is the only way I've found to create a password protected zip file. When I use it I get a deprecationwarning: PY_SSIZE_T_CLEAN will be required for '#' formats.

now, I have no control over that library, no ability to fix it - nor do I seem to have an easy alternative to using it - and it works fine. So the deprecation warning adds zero value to me - but it interferes with the UI of my tool - as it appears on stdout. Is there any way to suppress it/make it go away?

the way I'm calling it is:

   import pyminizip
   pyminizip.compress_multiple( [ prod_report ], [], f"C:/temp/report{name}.zip", "Password", 9 )
user202729
  • 3,358
  • 3
  • 25
  • 36
Darren Oakey
  • 2,894
  • 3
  • 29
  • 55
  • 1
    Are you sure that it's a bug in the library rather than a bug with how you use it? – user202729 Feb 18 '21 at 05:29
  • In the former case the easiest way would be to contact the library author and tell them to fix the bug, **or** find a more up-to-date fork and use it, **or** make one yourself. Find convoluted way to suppress the output (redirect `sys.stderr` might work) is not a good idea. – user202729 Feb 18 '21 at 05:30
  • 3
    Anyway post a [example] for how to create the error message. – user202729 Feb 18 '21 at 05:30
  • You can redefine stdout to be a stream of your own making that filters its input and outputs what makes it through the filter to stdout. Then you can look for and remove just this one message. - or just redirect to /dev/null if you don't need any output to show. – CryptoFool Feb 18 '21 at 05:31
  • adam - no I'm not - but either way - I want the warning to go away :) – Darren Oakey Feb 18 '21 at 05:31
  • If the python script is for one platform only, you could simply use a subprocess instead. Otherwise you could use `contextlib.redirect_stdout` or `redirect_stderr` to prevent it from printing – FalseDev Feb 18 '21 at 05:32
  • 1
    adam - zipfile doesn't allow you to write a password protected zip file - only read – Darren Oakey Feb 18 '21 at 05:33
  • @DarrenOakey ah you're so right -- my mistake! – Adam Smith Feb 18 '21 at 05:34
  • And what Python version are you using? 3.8 or 3.9? – user202729 Feb 18 '21 at 05:35
  • Looks like someone already filed an issue on the repository. https://github.com/smihica/pyminizip/issues/34 – user202729 Feb 18 '21 at 05:37
  • 1
    Does this answer your question? [How to disable Python warnings?](https://stackoverflow.com/questions/14463277/how-to-disable-python-warnings) – Brian McCutchon Feb 18 '21 at 05:38
  • @BrianMcCutchon (does it really work in this case? This is raised by a C API usage) – user202729 Feb 18 '21 at 05:40
  • The double-duplicate of the linked question above https://stackoverflow.com/questions/17250/create-an-encrypted-zip-file-in-python has several "other libraries" (workarounds in this case) – user202729 Feb 18 '21 at 05:40

1 Answers1

7
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning) 

got the answer from https://stackoverflow.com/a/879249/15213571

mark86v1
  • 182
  • 1
  • 13