【发布时间】:2017-08-02 13:27:05
【问题描述】:
我正在编写一个有时使用 HTTP 下载文件的 GTK 应用程序。由于我不想阻止正常执行,我显然不能使用 urllib 或 Requests,所以我尝试使用 GIO 来代替。但是,通过 HTTP 下载文件时,我收到了 GLib.Error: g-io-error-quark: Operation not supported (15)(file:// 工作正常)。
from gi.repository import Gio
print(Gio.File.new_for_uri("file:///etc/profile").load_contents(None))
print(Gio.File.new_for_uri("http://example.org").load_contents(None))
第一个语句(file://)按预期工作,但第二个语句(http://)给出了上述错误(下面的完整输出)。在我的真实程序中,我使用的是异步版本,但同步版本更短,并且报同样的错误。
(True, contents=b'# /etc/profile\n\n [-snip-]')
Traceback (most recent call last):
File "/tmp/gio.py", line 3, in <module>
print(Gio.File.new_for_uri("http://example.org").load_contents(None))
GLib.Error: g-io-error-quark: Operation not supported (15)
【问题讨论】: