JurajNyiri / pytapo

Python library for communication with Tapo Cameras
MIT License
292 stars 60 forks source link

Access TP-Link Tapo c110 (Invalid auth data, missing hostname trim) #45

Closed robozb closed 1 year ago

robozb commented 1 year ago

Dear Developers,

What do You think, can I access my TP-Link C110 With this library? The first trying wasn't successful :( I'd like to turn on/off the "privacy mode".

Thanks: Bela

(virt) pytapo@rpi4:~/pytapo $ python3 tapo.py
Traceback (most recent call last):
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa4875070>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.0.27%20', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa4875070>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pytapo/pytapo/tapo.py", line 7, in <module>
    tapo = Tapo(host, user, password)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 45, in __init__
    self.basicInfo = self.getBasicInfo()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 364, in getBasicInfo
    return self.executeFunction(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 105, in executeFunction
    data = self.performRequest(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 128, in performRequest
    self.ensureAuthenticated()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 65, in ensureAuthenticated
    return self.refreshStok()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 78, in refreshStok
    res = requests.post(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.0.27%20', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa4875070>: Failed to establish a new connection: [Errno -2] Name or service not known'))
robozb commented 1 year ago

OK, the problem is solved partialy, I mistyped the IP address string(+1 space) "192.168.0.27 " ->"192.168.0.27" But now the auth data is incorrect, even so I can connect to the camera(stream) by VLC:

Anyway which credentials should I use?

I mention it this is a Tapo-C110 :)

Thanks!

(virt) pytapo@rpi4:~/pytapo $
python3 tapo.py
Traceback (most recent call last):
  File "/home/pytapo/pytapo/tapo.py", line 7, in <module>
    tapo = Tapo(host, user, password)
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 45, in __init__
    self.basicInfo = self.getBasicInfo()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 364, in getBasicInfo
    return self.executeFunction(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 105, in executeFunction
    data = self.performRequest(
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 128, in performRequest
    self.ensureAuthenticated()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 65, in ensureAuthenticated
    return self.refreshStok()
  File "/home/pytapo/pytapo/virt/lib/python3.9/site-packages/pytapo/__init__.py", line 84, in refreshStok
    raise Exception("Invalid authentication data")
Exception: Invalid authentication data
JurajNyiri commented 1 year ago

You need to create a camera account via the Tapo app first. Or you can use "admin" username and your tplink cloud password, some cameras allow control only through that account.

You do not need to disable 2FA.

robozb commented 1 year ago

Dear @JurajNyiri,

2A16217C-48E8-473B-8F67-22F504B0316E

What user/password are good here throws exception in the python prg :(

The host is the ip address of the camera?

Happy New Year!

Bela

robozb commented 1 year ago

None of the checked user/password pairs were good :(

Neither the app credentials nor the camera’s :(

Both case throw auth exception.

04B2002E-349B-4330-9012-ED776FA3BFF7

Thanks for any help!

JurajNyiri commented 1 year ago

Use "admin" username and your tplink cloud password.

robozb commented 1 year ago

Dear @JurajNyiri,

Awesome!!! Now I can access the camera :)

So the credentials: Username: "admin" Password: WEB/ (IOS)APP password (not the camera account password!) Host: IP of the camera on localhost!

Thanks: Bela

robozb commented 1 year ago

Incredible, the privacy settings works as well!

tapo.setPrivacyMode(False)

Thank you so much!