Merge branch 'thelostpolaris:master' into 'master'

Fix confusing issues when hostname has no protocol

Closes #302

See merge request sublime-music/sublime-music!63
This commit is contained in:
Sumner Evans
2021-06-13 14:54:41 +00:00
2 changed files with 31 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ had to install to develop the app. In general, the requirements are:
#### Specific Requirements for Various Distros/OSes #### Specific Requirements for Various Distros/OSes
* **NixOS:** use the `shell.nix` which will also run the `poetry install` * **NixOS:** use the `shell.nix` which will also run the `poetry install`
* **Arch Linux:** `pacman -S libnm-glib libnotify python-gobject` * **Arch Linux:** `pacman -S libnm-glib libnotify python-gobject gobject-introspection`
* **macOS (Homebrew):** `brew install mp3 gobject-introspection pkg-config pygobject3 gtk+3 adwaita-icon-theme` * **macOS (Homebrew):** `brew install mp3 gobject-introspection pkg-config pygobject3 gtk+3 adwaita-icon-theme`
### Installing ### Installing

View File

@@ -444,18 +444,41 @@ class SubsonicAdapter(Adapter):
logging.info("Using mock data") logging.info("Using mock data")
result = self._get_mock_data() result = self._get_mock_data()
else: else:
result = requests.get( if url.startswith("http://") or url.startswith("https://"):
url, result = requests.get(
params=params, url,
verify=self.verify_cert, params=params,
timeout=timeout, verify=self.verify_cert,
) timeout=timeout,
)
else:
# if user creates a serverconf address w/o protocol, we'll
# attempt to fix it and store it in hostname
# TODO (#305) #hostname currently preprends https:// if
# protocol isn't defined this might be able to be taken out
try:
logging.info("Hostname: %r has no protocol", self.hostname)
result = requests.get(
"https://" + url,
params=params,
verify=self.verify_cert,
timeout=timeout,
)
self.hostname = "https://" + url.split("/")[0]
except Exception:
result = requests.get(
"http://" + url,
params=params,
verify=self.verify_cert,
timeout=timeout,
)
self.hostname = "http://" + url.split("/")[0]
if result.status_code != 200: if result.status_code != 200:
raise ServerError( raise ServerError(
result.status_code, f"{url} returned status={result.status_code}." result.status_code, f"{url} returned status={result.status_code}."
) )
# Any time that a server request succeeds, then we win. # Any time that a server request succeeds, then we win.
self._server_available.value = True self._server_available.value = True
self._last_ping_timestamp.value = datetime.now().timestamp() self._last_ping_timestamp.value = datetime.now().timestamp()