Skip to content

Commit

Permalink
Fix login with space in password (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenxn authored May 14, 2020
1 parent 9a523c7 commit c96d2b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions synology_dsm/synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Class to interact with Synology DSM."""
import socket
import urllib3
import six
from requests import Session
from requests.exceptions import RequestException
from simplejson.errors import JSONDecodeError
Expand All @@ -24,6 +25,11 @@
from .api.storage.storage import SynoStorage
from .const import API_AUTH, API_INFO

if six.PY2:
from future.moves.urllib.parse import quote
else:
from urllib.parse import quote # pylint: disable=import-error,no-name-in-module


class SynologyDSM(object):
"""Class containing the main Synology DSM functions."""
Expand Down Expand Up @@ -232,14 +238,21 @@ def _request(

return response

def _execute_request(self, method, url, **kwargs):
def _execute_request(self, method, url, params, **kwargs):
"""Function to execute and handle a request."""
# Execute Request
try:
if method == "GET":
resp = self._session.get(url, **kwargs)
if six.PY2:
items = params.iteritems()
else:
items = params.items()
encoded_params = "&".join(
"%s=%s" % (key, quote(str(value))) for key, value in items
)
resp = self._session.get(url, params=encoded_params, **kwargs)
elif method == "POST":
resp = self._session.post(url, **kwargs)
resp = self._session.post(url, pararms=params, **kwargs)

self._debuglog("Request url: " + resp.url)
self._debuglog("Request status_code: " + str(resp.status_code))
Expand Down
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def __init__(
self.disks_redundancy = "RAID" # RAID or SHR[number][_EXPANSION]
self.error = False

def _execute_request(self, method, url, **kwargs):
url += urlencode(kwargs["params"])
def _execute_request(self, method, url, params, **kwargs):
url += urlencode(params)

if "no_internet" in url:
raise SynologyDSMRequestException(
Expand Down

0 comments on commit c96d2b2

Please sign in to comment.