N4S4 / synology-api

A Python wrapper around Synology API
MIT License
368 stars 138 forks source link

trying to connect and upload file with filestation #62

Closed comes04 closed 3 years ago

comes04 commented 3 years ago

Hello, I have been using the "python-synology 1.0.0" library and I have managed to connect to my NAS by putting ("sensor12345.synology.me", "5000", "username", "password") but with this library I can't upload files.

I have seen this other “synology-api” library that I think can help me upload files to my NAS more easily. The thing is that I try with:

from synology_api import filestation fl = filestation.FileStation ('sensor12345.synology.me', '5000', 'username', 'password') fl.get_info ()

and it gives me the following error:

Traceback (most recent call last): File "C: /Users/moti/PycharmProjects/GUItutorial/venv/synology_wrapper_test.py", line 7, in fl = filestation.FileStation ('sensor12345.synology.me', '5000', 'username', 'password') File "C: \ Users \ moti \ PycharmProjects \ GUItutorial \ venv \ lib \ site-packages \ synology_api \ filestation.py", line 34, in init self.session.login ('FileStation') File "C: \ Users \ moti \ PycharmProjects \ GUItutorial \ venv \ lib \ site-packages \ synology_api \ auth.py", line 30, in login self._sid = session_request.json () ['data'] ['sid'] KeyError: 'data'

I hope you can help me. Thanks in advance

N4S4 commented 3 years ago

is better if you update your version to the latest v0.1.3.3, and soon there is going to be a new version which fix an error in upload file functions included in PR #61 by @longyn with few more improvements with PR #59

comes04 commented 3 years ago

Hi, I already use v0.1.3.3, I just want to make sure if there is something that I'm doing wrong or it is a problem of the library. It could be the NAS model or it's version? I'm using the Synology DS920+ with DSM version:DSM 6.2.4-25556 As I said before, with the “python-synology” librarie I'm able to connect with this same parameters ('hostname', 'port', 'username', 'password') Thanks again.

longyn commented 3 years ago
  1. If you use https, your should pass secure = True to FileStation
  2. Or add a log and print out the value, and then check the error with synology dev doc.
 print(session_request.json ())
comes04 commented 3 years ago

Hi there, I just try with the following as you said: fl = filestation.FileStation('sensor12345.synology.me', '5001', 'user', 'pass', secure=True, cert_verify=True) it just respond me with the same error... However, thanks for the quick response

N4S4 commented 3 years ago

Do you have a valid certificate on your synology? Try without cert_verify set it to False

N4S4 commented 3 years ago

Plus try to add https at the beginning of the link

comes04 commented 3 years ago

Hi N4S4, thanks for all your help. I don't een know what is a valid certificate for synology so I guess no. I tried without cert_verify so as: fl = filestation.FileStation('sensor12345.synology.me', '5001', 'usr', 'key', secure=True) and i get mostly the same error:

C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host 'sensor12345.synology.me'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings warnings.warn( Traceback (most recent call last): File "C:/Users/moti/PycharmProjects/GUItutorial/venv/synology_wrapper_test.py", line 9, in fl = filestation.FileStation('sensor12345.synology.me', '5001', 'usr', 'key', secure=True) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\synology_api\filestation.py", line 34, in init self.session.login('FileStation') File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\synology_api\auth.py", line 30, in login self._sid = session_request.json()['data']['sid'] KeyError: 'data'

Also I tried putting https:// at the beginning as: fl = filestation.FileStation('https://sensor12345.synology.me', '5001', 'usr', 'key', secure=True) and i get another error:

Traceback (most recent call last): File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connection.py", line 169, in _new_conn conn = connection.create_connection( File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "C:\Users\moti\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn conn.connect() File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connection.py", line 353, in connect conn = self._new_conn() File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connection.py", line 181, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x03F80B08>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen retries = retries.increment( File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\urllib3\util\retry.py", line 573, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //sensor12345.synology.me:5001/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=Jaime+Comes&passwd=josujaime04&session=FileStation&format=cookie (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x03F80B08>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/moti/PycharmProjects/GUItutorial/venv/synology_wrapper_test.py", line 9, in fl = filestation.FileStation('https://sensor12345.synology.me', '5001', 'usr', 'key', secure=True) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\synology_api\filestation.py", line 34, in init self.session.login('FileStation') File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\synology_api\auth.py", line 29, in login session_request = requests.get(self._base_url + login_api, param, verify=self._verify) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\requests\api.py", line 76, in get return request('get', url, params=params, kwargs) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, kwargs) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\requests\sessions.py", line 655, in send r = adapter.send(request, kwargs) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\requests\adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //sensor12345.synology.me:5001/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=Jaime+Comes&passwd=josujaime04&session=FileStation&format=cookie (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x03F80B08>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

Any more ideas?

longyn commented 3 years ago
  1. If you use https, your should pass secure = True to FileStation
  2. Or add a log and print out the value, and then check the error with synology dev doc.
 print(session_request.json ())

Did you try option 2?

comes04 commented 3 years ago

yes, i try it like this: fl = filestation.FileStation('sensor12345.synology.me', '5001', 'usr', 'key', secure=True) print(session_request.json())

and it doesn't print anything, I just get the common error:

Traceback (most recent call last): File "C:/Users/moti/PycharmProjects/GUItutorial/venv/synology_wrapper_test.py", line 7, in fl = filestation.FileStation('sensor12345.synology.me', '5001', 'usr', 'key', secure=True) File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\synology_api\filestation.py", line 34, in init self.session.login('FileStation') File "C:\Users\moti\PycharmProjects\GUItutorial\venv\lib\site-packages\synology_api\auth.py", line 30, in login self._sid = session_request.json()['data']['sid'] KeyError: 'data'

N4S4 commented 3 years ago

Did you try if you can manage to login on the same network?

longyn commented 3 years ago

so please try to print out what's the value of session_request.json() in auth.py, you'll get the more useful info..

N4S4 commented 3 years ago

Issue closed or inactivity