@@ -54,7 +54,8 @@ def _get_or_create_device_id(self) -> str:
5454 if device_id :
5555 return device_id
5656 device_id = str (uuid .uuid4 ())
57- with open (self ._device_id_file , "w" ) as f :
57+ fd = os .open (self ._device_id_file , os .O_WRONLY | os .O_CREAT | os .O_TRUNC , 0o600 )
58+ with os .fdopen (fd , "w" ) as f :
5859 f .write (device_id )
5960 return device_id
6061
@@ -69,7 +70,8 @@ def _load_tokens(self) -> dict[str, str]:
6970
7071 def _save_tokens (self , tokens : dict [str , str ]) -> None :
7172 self ._tokens = tokens
72- with open (self ._token_file , "w" ) as f :
73+ fd = os .open (self ._token_file , os .O_WRONLY | os .O_CREAT | os .O_TRUNC , 0o600 )
74+ with os .fdopen (fd , "w" ) as f :
7375 json .dump (tokens , f , indent = 2 )
7476
7577 def _headers (self ) -> dict [str , str ]:
@@ -168,11 +170,19 @@ def post(self, path: str, payload: dict[str, Any]) -> dict[str, Any] | None:
168170 self ._cache .enqueue_scrobble (path , payload )
169171 return None
170172 except urllib .error .HTTPError as exc :
171- xbmc .log (
172- f"[PunchPlay] HTTP { exc .code } on { path } — queuing" , xbmc .LOGWARNING
173- )
174- if self ._cache is not None :
175- self ._cache .enqueue_scrobble (path , payload )
173+ if 500 <= exc .code < 600 :
174+ # Transient server error — queue for retry.
175+ xbmc .log (
176+ f"[PunchPlay] HTTP { exc .code } on { path } — queuing" , xbmc .LOGWARNING
177+ )
178+ if self ._cache is not None :
179+ self ._cache .enqueue_scrobble (path , payload )
180+ else :
181+ # Permanent client error (4xx) — drop, retrying won't help.
182+ xbmc .log (
183+ f"[PunchPlay] HTTP { exc .code } on { path } — dropping (permanent error)" ,
184+ xbmc .LOGWARNING ,
185+ )
176186 return None
177187
178188 # ------------------------------------------------------------------
0 commit comments