Python error: AttributeError: __exit__

I just had a 30 minutes worth of debugging on a stupid mistake I made. I wanted to check the free space on the target server before I actually start to do the cloning of a database in the python framework we wrote for automating DBA tasks. The check was pretty simple:

But this raised an error: AttributeError: __exit__

I’ve spent almost 30 minutes when I realized the os.statvfs returns and “old style” object which doesn’t have __exit__ method by default. [1]

Changed the code to not use with [2] fixed the problem:

[1] object type in Python:

[2] read more about with statement:

You might like these too

BitTornado library forked by me on GitHub I just forked and committed some patches to the BitTornado library on GitHub. Right now I only committ...
Sunburnt Solr spatial filter support I've added spatial filtering to the sunburnt library. The feature is now available with filter_spatial function. Example usage Currently this will...
Dataimport handler for Sunburnt Solr python librar... Dataimport handler I had to trigger the dataimporter delta-import command from the code so I added support for this function. Example: Followin...

About charlesnagy

I'm out of many things mostly automation expert, database specialist, system engineer and software architect with passion towards data, searching it, analyze it, learn from it. I learn by experimenting and this blog is a result of these experiments and some other random thought I have time to time.
Bookmark the permalink.