Confusing behavior of PYTHONWARNINGS

Meowxiik meowxiik at gmail.com
Sat Sep 16 04:17:20 EDT 2023


Hello,

For the third time I am trying to work with `PYTHONWARNINGS` filter, and 
for the third time I am having a terrible time. I'd like to seek your 
assistance, I have a few questions:

**Question 1:** Does the environment variable only matter at python 
interpreter startup time? If I set the same variable before python 
start, it seems to work, but it doesn't work trough os.environ. It does 
appear to be hinted at in the docs, but imho not clear enough.

**Question 2:** Why do the following filters not work for filtering 
`urllib3.exceptions.InsecureRequestWarning`

- `PYTHONWARNINGS=ignore:::urllib3.exceptions`

- `PYTHONWARNINGS=ignore:::urllib3`

- `PYTHONWARNINGS=ignore:::urllib3.exceptions`

- `PYTHONWARNINGS=ignore::urllib3.exceptions.InsecureRequestWarning`

None of these filter the warning. The last one has the audacity to 
complain about "invalid module name: 'urllib3.exceptions'" which is very 
confusing to me, given that that specific module is fully importable 
during runtime, which I have tested. The only one I managed to get 
working is `ignore:Unverified`, where "Unverified" is the first word of 
the actual message, however I truly strongly dislike this solution.

Thank you for any help,

Richard



More information about the Python-list mailing list