rclone-bin-api 1.0.6__tar.gz → 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rclone-bin-api
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Rclone API for Python including the Rclone binaries.
5
5
  Author-email: Michael G <me@mgineer85.de>
6
6
  Maintainer-email: Michael G <me@mgineer85.de>
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Classifier: Programming Language :: Python :: 3.14
15
15
  Requires-Python: >=3.11
16
16
  Description-Content-Type: text/markdown
17
+ Requires-Dist: httpx2
17
18
 
18
19
  # Rclone Api for Python including Rclone binaries
19
20
 
@@ -2,7 +2,7 @@
2
2
  [project]
3
3
  name = "rclone-bin-api"
4
4
  description = "Rclone API for Python including the Rclone binaries."
5
- version = "1.0.6"
5
+ version = "1.0.7"
6
6
  authors = [{ name = "Michael G", email = "me@mgineer85.de" }]
7
7
  maintainers = [{ name = "Michael G", email = "me@mgineer85.de" }]
8
8
  requires-python = ">=3.11"
@@ -18,7 +18,9 @@ classifiers = [
18
18
  keywords = ["rclone"]
19
19
 
20
20
 
21
- dependencies = []
21
+ dependencies = [
22
+ "httpx2"
23
+ ]
22
24
 
23
25
 
24
26
  [project.urls]
@@ -6,7 +6,7 @@ from rclone_api.api import RcloneApi
6
6
  if __name__ == "__main__":
7
7
  logging.basicConfig(
8
8
  stream=sys.stdout,
9
- level=logging.DEBUG,
9
+ level=logging.WARNING,
10
10
  format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s",
11
11
  )
12
12
 
@@ -1,13 +1,13 @@
1
1
  import atexit
2
- import json
3
2
  import logging
4
3
  import subprocess
5
4
  import threading
6
5
  import time
7
- import urllib.error
8
- import urllib.request
9
6
  from pathlib import Path
10
7
  from typing import Any, Literal
8
+ from urllib.parse import quote
9
+
10
+ import httpx2
11
11
 
12
12
  from . import BINARY_PATH
13
13
  from .dto import AsyncJobResponse, ConfigListremotes, CoreStats, CoreVersion, JobList, JobStatus, LsJsonEntry, PubliclinkResponse
@@ -19,7 +19,7 @@ logger = logging.getLogger(name="rclone_api")
19
19
  class RcloneApi:
20
20
  def __init__(
21
21
  self,
22
- bind="127.0.0.1:5572", # bind to IPv4 127.0.0.1 until https://github.com/rclone/rclone-web/issues/71 is resolved
22
+ bind="127.0.0.1:5572", # always bind to a local address by default because we have auth disabled for convenience
23
23
  bind_gui="127.0.0.1:5573", # bind to IPv4 127.0.0.1 until https://github.com/rclone/rclone-web/issues/71 is resolved
24
24
  log_file: Path | None = None,
25
25
  log_level: Literal["DEBUG", "INFO", "NOTICE", "ERROR"] = "NOTICE",
@@ -39,7 +39,7 @@ class RcloneApi:
39
39
  self.__bwlimit = bwlimit
40
40
  self.__config_file = config_file
41
41
 
42
- self.__connect_addr = f"http://{bind}"
42
+ self.__connect_addr = f"http://{self.__bind_addr}"
43
43
  self.__process = None
44
44
  self.__rclone_bin = BINARY_PATH
45
45
  self.__startstop_lock = threading.Lock()
@@ -62,19 +62,26 @@ class RcloneApi:
62
62
  # since rclone 1.74.0 a new built-in webgui is avail.
63
63
  # start using gui to enable the gui, otherwise only rcd which just exposes the api
64
64
  if self.__enable_webui:
65
- logger.info("starting rclone with gui enabled")
65
+ logger.debug("Starting Rclone with gui enabled")
66
+ gui_link = f"http://{self.__bind_addr_gui.rstrip('/')}/login?url="
67
+ api_link = f"http://{self.__bind_addr}"
68
+ logger.info(f"Access Rclone using the following link {gui_link}{quote(api_link, '')}")
66
69
  rc_cmd = "gui"
67
70
  rc_cmd_args = [
68
- "--rc-no-auth",
71
+ f"--addr={self.__bind_addr_gui}", # gui options
72
+ "--no-auth",
69
73
  "--no-open-browser",
70
- f"--api-addr={self.__bind_addr}",
71
- f"--addr={self.__bind_addr_gui}",
74
+ # "--user=rclone",
75
+ # "--pass=123",
76
+ f"--api-addr={self.__bind_addr}", # rcd options
77
+ "--rc-no-auth", # rcd server option
78
+ "--rc-allow-origin=*",
72
79
  ]
73
80
  else:
74
- logger.info("starting rclone with remote command daemon (api only, no gui)")
81
+ logger.debug("Starting Rclone with remote command daemon (api only, no gui)")
75
82
  rc_cmd = "rcd"
76
83
  rc_cmd_args = [
77
- "--rc-no-auth",
84
+ "--rc-no-auth", # only "safe" if bound to localhost
78
85
  f"--rc-addr={self.__bind_addr}",
79
86
  ]
80
87
 
@@ -152,22 +159,19 @@ class RcloneApi:
152
159
  def _post(self, endpoint: str, data: dict[str, Any] | None = None):
153
160
  TIMEOUT = 90
154
161
 
155
- req = urllib.request.Request(
156
- url=f"{self.__connect_addr}/{endpoint}",
157
- data=json.dumps(data or {}).encode("utf-8"),
158
- headers={"Content-Type": "application/json"},
159
- method="POST",
160
- )
161
-
162
162
  try:
163
- with urllib.request.urlopen(req, timeout=TIMEOUT) as resp:
164
- raw_resp: bytes = resp.read()
165
- response_json = json.loads(raw_resp.decode("utf-8"))
166
-
167
- except urllib.error.HTTPError as exc: # non 200 HTTP codes
168
- raw_exc: bytes = exc.read()
169
- response_json = json.loads(raw_exc.decode("utf-8"))
170
- raise RcloneProcessException.from_dict(response_json) from exc
163
+ res = httpx2.request(
164
+ url=f"{self.__connect_addr}/{endpoint}",
165
+ json=data or {},
166
+ headers={"Content-Type": "application/json"},
167
+ method="POST",
168
+ timeout=httpx2.Timeout(TIMEOUT),
169
+ )
170
+ res.raise_for_status()
171
+ response_json = res.json()
172
+
173
+ except httpx2.HTTPStatusError as exc: # non 200 HTTP codes
174
+ raise RcloneProcessException(error=exc.response.text, input=data, status=exc.response.status_code, path=endpoint) from exc
171
175
  except TimeoutError as exc:
172
176
  raise RcloneConnectionException(f"Operation timed out after {TIMEOUT}s. To copy large files consider using _async methods.") from exc
173
177
  except Exception as exc: # all other errors
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rclone-bin-api
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Rclone API for Python including the Rclone binaries.
5
5
  Author-email: Michael G <me@mgineer85.de>
6
6
  Maintainer-email: Michael G <me@mgineer85.de>
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Classifier: Programming Language :: Python :: 3.14
15
15
  Requires-Python: >=3.11
16
16
  Description-Content-Type: text/markdown
17
+ Requires-Dist: httpx2
17
18
 
18
19
  # Rclone Api for Python including Rclone binaries
19
20
 
@@ -10,6 +10,7 @@ src/rclone_api/exceptions.py
10
10
  src/rclone_bin_api.egg-info/PKG-INFO
11
11
  src/rclone_bin_api.egg-info/SOURCES.txt
12
12
  src/rclone_bin_api.egg-info/dependency_links.txt
13
+ src/rclone_bin_api.egg-info/requires.txt
13
14
  src/rclone_bin_api.egg-info/top_level.txt
14
15
  src/tests/test_exceptions.py
15
16
  src/tests/test_rclone.py
File without changes
File without changes
File without changes