49

I just finished installing my MySQLdb package for Python 2.6, and now when I import it using import MySQLdb, a user warning appear will appear

/usr/lib/python2.6/site-packages/setuptools-0.8-py2.6.egg/pkg_resources.py:1054:
UserWarning: /home/sgpromot/.python-eggs is writable by group/others and vulnerable 
to attack when used with get_resource_filename. Consider a more secure location 
(set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
  warnings.warn(msg, UserWarning)

Is there a way how to get rid of this?

3 Answers 3

79

You can change ~/.python-eggs to not be writeable by group/everyone. I think this works:

chmod g-wx,o-wx ~/.python-eggs
Sign up to request clarification or add additional context in comments.

1 Comment

In a situation where everything must be writable by group (developers, in this case), there needs to be a userland way of suppressing this and saying "yes, I'm well aware the other two users active in this group can write to the egg folder, that's intentional. the global umask is 0002."
34

You can suppress warnings using the -W ignore:

python -W ignore yourscript.py

If you want to supress warnings in your script (quote from docs):

If you are using code that you know will raise a warning, such as a deprecated function, but do not want to see the warning, then it is possible to suppress the warning using the catch_warnings context manager:

import warnings

def fxn():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()

While within the context manager all warnings will simply be ignored. This allows you to use known-deprecated code without having to see the warning while not suppressing the warning for other code that might not be aware of its use of deprecated code. Note: this can only be guaranteed in a single-threaded application. If two or more threads use the catch_warnings context manager at the same time, the behavior is undefined.

If you just want to flat out ignore warnings, you can use filterwarnings:

import warnings
warnings.filterwarnings("ignore")

4 Comments

It works, thanks! But I am considering a permanent fix for this, without using -W ignore.
It's bad practice to ignore warnings, especially security related warnings
Yes, but some warnings just useful and wasting your time, like UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling wich torch trowing, especially annoying if you test some fucntion and see about 50 the same repeated warnings.
@ConorPatrick Nope. Bad designed warnings will only flood your screen and sometimes you have to mute them.
0

just a comment what helped me. I needed a solution which is on top of my main-script so I can run it easily over my IDE.

import warnings
warnings.filterwarnings("ignore", message="Failed to load image Python extension")

in the message-Argument I had to insert the first few messages of my "UserWarning"-Message (which I wanted to surpress)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.