System settings: Download tab fails with int() argument must be ... not 'NoneType' - spices server serves JSON without Content-Length

未关闭
#14,140 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 8 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend, desktop

调研方向

Read files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py, focusing on _url_retrieve() and _update_progress(), then reproduce the Download tab failure with a chunked response that has no Content-Length header. The issue provides the specific changes and reports that fetching applet index.json and thumbnails succeeds afterward; check whether this 6.6.x fix is still needed, since the issue says master was rewritten and is unaffected.

由索引模型根据 Issue 内容生成。

描述

Summary

Opening the "Download" tab in System Settings -> Applets (also Desklets, Extensions, Actions, Themes) shows an error dialog:

An error occurred while trying to access the server. Please try again in a little while.

Details: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

The list of available spices can never be loaded - ~/.cache/cinnamon/spices/<type>/index.json stays empty (the partially downloaded file is removed on error).

Reproduce

  1. cinnamon-settings -> Applets -> Download tab (this triggers refresh_cache()).
  2. Observe that the request to cinnamon-spices.linuxmint.com/json/applets.json has no Content-Length header when made through requests/urllib3:
curl -sS -D - -o /dev/null "https://cinnamon-spices.linuxmint.com/json/applets.json" | grep -iE 'HTTP/|content-length|transfer-encoding'
# HTTP/2 200 ... (HEAD reports content-length)

python3 -c "
import requests
r = requests.get('https://cinnamon-spices.linuxmint.com/json/applets.json', stream=True)
print(r.status_code, r.headers.get('content-length'), r.headers.get('transfer-encoding'))"
# 200 None chunked   <-- no content-length when requested with Accept-Encoding: gzip

The server now serves the JSON indexes with Transfer-Encoding: chunked + Content-Encoding: gzip, so the content-length header is absent.

Root cause

files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py:

def _url_retrieve(self, url, outfd, reporthook, binary):
    ...
    response = requests.get(url, proxies=proxy_info, stream=True, timeout=15)
    assert response.ok
    totalSize = int(response.headers.get('content-length'))   # <-- None -> TypeError

The exception is caught in _download() and surfaced as "An error occurred while trying to access the server...".

Fix

--- a/files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py
+++ b/files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py
@@ -420,7 +420,8 @@ class Spice_Harvester(GObject.Object):
             response = requests.get(url, proxies=proxy_info, stream=True, timeout=15)
             assert response.ok
 
-            totalSize = int(response.headers.get('content-length'))
+            content_length = response.headers.get('content-length')
+            totalSize = int(content_length) if content_length is not None else 0
 
             for data in response.iter_content(chunk_size=blockSize):

Plus a guard in _update_progress so the progress bar does not run away when the total size is unknown:

@@ -328,7 +328,12 @@
             text = _("Downloading images:") + f" {current}/{total}"
             self._set_progressbar_text(text)
         else:
-            fraction = count * blockSize / float((totalSize / blockSize + 1) * blockSize)
+            if totalSize > 0:
+                fraction = count * blockSize / float((totalSize / blockSize + 1) * blockSize)
+            else:
+                # No content-length header (chunked response) - fall back to a
+                # progress estimate based on the number of chunks received.
+                fraction = count / float(count + 1)
 
         self._set_progressbar_fraction(fraction)

Verification with the patched code: the real Spice_Harvester('applet').refresh_cache() downloads index.json (275 applets, 674698 bytes) plus all thumbnails without errors. Static assets (icons/screenshots) are still served with Content-Length - only the JSON index downloads break.

Environment

  • Cinnamon 6.6.7 (Gentoo Linux), Python 3.14, requests 2.34.2 / urllib3 2.7.0

Note

In master, Spices.py was rewritten on top of cinnamon.harvester (non-streamed requests), which is not affected. Suggest backporting the fix to 6.6.x, otherwise this can be closed as fixed-in-master.

主要语言
JavaScript
星标
5.7k
派生
941
平均合并
6 天 18 小时
30 天内合并 PR
12

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

linuxmint/cinnamon 的其他 Issue

查看 linuxmint/cinnamon 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。