簡體   English   中英

使用GLib的GIO API時不支持HTTP

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM