BUG: close file-like objects returned by urlopen

Fix `ResourceWarning: unclosed file` on Python 3
Merge pull request #3925 from charris/backport-1.7-3923

backport-1.7-3923