Ignoring deprecation warnings in Twill/Python
Tuesday, May 19th, 2009I wrote a small command-line utility with Twill and Python that I use to scrape prices from our booking engine at work. The Python script worked fine when I ran it on my Mac/Python2.5 but Twill (or mechanize, to be exact) was giving deprecation warnings when I tried to run it on Windows/Python2.6.1.
C:\Users\Administrator\twill\other_packages\_mechanize_dist\_auth.py:14: DeprecationWarning: the md5 module is deprecated; use hashlib instead import re, base64, urlparse, posixpath, md5, sha, sys, copy C:\Users\Administrator\twill\other_packages\_mechanize_dist\_auth.py:14: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import re, base64, urlparse, posixpath, md5, sha, sys, copy
The solution is trivial; to supress deprecation warnings in python, just add an ingore filter before the line where you import Twill (or any other offending library). The alert reader may notice that the second part of the filterwarnings argument (’.*’) is a regular expression; this would allow you to tailor exactly which deprecation warnings you wish to propagate to the command-line.
import warnings
warnings.filterwarnings('ignore', '.*')
from twill.commands import *
import twill