[英]HTTP not supported when using GLib’s GIO APIs
我正在编写一个GTK应用程序,有时会使用HTTP下载文件。 由于我不想阻止正常执行,因此显然不能使用urllib或Requests,因此我尝试使用GIO。 但是,我收到了GLib.Error: g-io-error-quark: Operation not supported (15)
通过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)
确保您已安装GVFS的http
后端,并且您的程序可以访问gvfsd
在其上运行的D-Bus会话总线。
GVFS后端通常以gvfs-backends
类的分发包形式提供。
默认情况下,GIO不支持加载file://
URI以外的URI。 对于所有其他URI,它与GVFS守护程序进行通信,该守护程序依次执行实际的I / O。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.