diff --git a/IPython/core/magic.py b/IPython/core/magic.py index cebec54..9bba32c 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2163,6 +2163,7 @@ Currently the magic system has the following functions:\n""" raise ValueError('%%load only works with .py files: %s' % arg_s) if remote_url: import urllib2 + fileobj = urllib2.urlopen(arg_s) # While responses have a .info().getencoding() way of asking for # their encoding, in *many* cases the return value is bogus. In # the wild, servers serving utf-8 but declaring latin-1 are @@ -2171,8 +2172,8 @@ Currently the magic system has the following functions:\n""" # rely on the headers. Short of building complex encoding-guessing # logic, going with utf-8 is a simple solution likely to be right # in most real-world cases. - with urllib2.urlopen(arg_s) as fileobj: - linesource = fileobj.read().decode('utf-8', 'replace').splitlines() + linesource = fileobj.read().decode('utf-8', 'replace').splitlines() + fileobj.close() else: with open(arg_s) as fileobj: linesource = fileobj.read().splitlines()