为什么 urllib.request.urlretrieve 不将控制转移到下一条指令

Why urllib.request.urlretrieve not transfers control to next instruction

在解释器中 'urllib.request.urlretrieve' 像这样工作很好:

Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>>urllib.request.urlretrieve('https://download.owncloud.org/download/repositories/stable/Ubuntu_15.10/Release.key', 'Release.key')
('Release.key', <http.client.HTTPMessage object at 0x7fa008f76518>)

在这个函数中不起作用:

def owncloudI():
    print(ok('Installing OwnCloud...\n'))
    urllib.request.urlretrieve('https://download.owncloud.org/download/repositories/stable/Ubuntu_15.10/Release.key', 'Release.key') #<---- stuck here
    call(['apt-key', 'add', 'Release.key'])
    rep = open('/etc/apt/sources.list.d/owncloud.list', 'a')
    print('deb http://download.owncloud.org/download/repositories/stable/Ubuntu_15.10/', file=rep)
    rep.close()
    call(['apt-get', 'update'])
    call(['apt-get', 'install', 'owncloud'])

使用 sudo 启动代码并在 /tmp cat 中执行,因此我认为权限没问题。也许有人已经解决了类似的问题。

解决这个问题
with urllib.request.urlopen('https://download.owncloud.org/download/repositories/stable/Ubuntu_15.10/Release.key') as response, open('resp.key', 'wb') as out_file:
    data = response.read()
    out_file.write(data)