tapo-cli icon indicating copy to clipboard operation
tapo-cli copied to clipboard

Unable to login

Open Proulxs opened this issue 7 months ago • 8 comments

After alot of work trying to understand Linux and getting everything setup and having to work with venv to allow to run I finally succeed to open tapo-cli.py login command and give my email, password, and also MFA code. But then I get: Something went wrong: { "codeRemainAttempts": 0, "accountApiUrl": "https://use1-account-api.i.tplinkcloud.com", "lockedMinutes": 0, "appServerUrl": "https://n-use1-wap-gw.tplinkcloud.com", "errorCode": "0", "token": "", "errorMsg": "Success", "accountId": "", "regionCode": "CA", "regTime": "2025-05-30 18:15:35", "nickname": "emilie", "codeFailedAttempts": 0, "email": "****", "appServerUrlV2": "https://n-use1-wap.i.tplinkcloud.com" }

(I removed some personal info where you see ****) It show success and give me a token but it doesn't seem to register those information and when I try to use any other commands it just tell me to login first. Is the code still usable with current safety updates and I'm just completly lost? I'm way out of my league but this seem to be the only possible option to download more than a few clips from Tapo Care. I need to download a few hundreds of clip per day for a few days and the app does not allows that except doing one by one which is not an option :(

Proulxs avatar Jun 11 '25 16:06 Proulxs

It seems like the great engineers at TP-Link have probably made a change to the API and are now sending back "Success" as an error message, which triggers an unnecessary error here:

https://github.com/dimme/tapo-cli/blob/62c2e39f0f9c3afbe35166795d7c00c4112e25c3/tapo-cli.py#L173-L174

Commenting these lines out works fine as a workaround and I'm able to both list and download videos.

I say "workaround", but I don't even think it's necessary to check the errorMsg in the first place, since the code always checks for errorCode being 0 anyway, but maybe I'm mistaken.

audeck avatar Jun 16 '25 07:06 audeck

This workaround indeed work and I finally got an access token saved. Small step forward then I try to list-videos or download them but it find none and it also say the datetime.datetime.utcfromtimestamp() is deprecated and to use timezone-aware objects instead:

Last X days [1]: 7 /mnt/c/simonp/tapo-cli/tapo-cli.py:287: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC). end_time = datetime.datetime.utcfromtimestamp(end_unixtime).strftime('%Y-%m-%d 00:00:00') /mnt/c/simonp/tapo-cli/tapo-cli.py:288: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC). start_time = datetime.datetime.utcfromtimestamp(start_unixtime).strftime('%Y-%m-%d 00:00:00') Found 0 videos for Tapo_C510W:

Good news is that it know it's a C510W. Small victory haha I though the deprecated code could be the issue so I tried changing it the code (line 287-288 and 318-319 to: end_time = datetime.datetime.fromtimestamp(end_unixtime, datetime.UTC).strftime('%Y-%m-%d 00:00:00') start_time = datetime.datetime.fromtimestamp(start_unixtime, datetime.UTC).strftime('%Y-%m-%d 00:00:00')

It fix the warning but did not find any video still.

Proulxs avatar Jun 17 '25 14:06 Proulxs

Okay I made a bit of a progress; I tried list-devices and learned that region is us-east-1 so I'm trying (without success) to change the line 59. Original says: https://euw1-app-tapo-care.i.tplinknbu.com My device says "appServerUrl": "https://n-use1-wap-gw.tplinkcloud.com", and "appServerUrlV2": "https://n-use1-wap-gw.i.tplinkcloud.com", So I tried to use https://n-use1-app-tapo-care.i.tplinknbu.com, https://n-use1-wap-gw.i.tplinkcloud.com and https://n-use1-wap-gw.tplinkcloud.com without success.

n-use1-app-tapo-care.i.tplinknbu.com give a very long message:

click to read Traceback (most recent call last):

File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connection.py", line 198, in _new_conn sock = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/util/connection.py", line 60, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/socket.py", line 963, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ socket.gaierror: [Errno -2] Name or service not known

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 787, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 488, in _make_request raise new_e File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 464, in _make_request self._validate_conn(conn) File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1093, in _validate_conn conn.connect() File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connection.py", line 704, in connect self.sock = sock = self._new_conn() ^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connection.py", line 205, in _new_conn raise NameResolutionError(self.host, self, e) from e urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x7d0371a45af0>: Failed to resolve 'n-use1-app-tapo-care.i.tplinknbu.com' ([Errno -2] Name or service not known)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/requests/adapters.py", line 667, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 841, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/urllib3/util/retry.py", line 519, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='n-use1-app-tapo-care.i.tplinknbu.com', port=443): Max retries exceeded with url: /v2/videos/list?deviceId=80214D07B8765D5714B0F010C5AAE54323839A8C&page=0&pageSize=3000&order=desc&startTime=2025-06-16%2000:00:00&endTime=2025-06-18%2000:00:00 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7d0371a45af0>: Failed to resolve 'n-use1-app-tapo-care.i.tplinknbu.com' ([Errno -2] Name or service not known)"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 366, in tapo() File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1442, in call return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1363, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1226, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke return callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 293, in list_videos videos = probe_endpoint_get(params, endpoint) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 119, in probe_endpoint_get res = get(url, params, headers_get(token)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 91, in get return json.loads(requests.get(url, params = params, headers = headers, verify = False).text) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/requests/adapters.py", line 700, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='n-use1-app-tapo-care.i.tplinknbu.com', port=443): Max retries exceeded with url: /v2/videos/list?deviceId=80214D07B8765D5714B0F010C5AAE54323839A8C&page=0&pageSize=3000&order=desc&startTime=2025-06-16%2000:00:00&endTime=2025-06-18%2000:00:00 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7d0371a45af0>: Failed to resolve 'n-use1-app-tapo-care.i.tplinknbu.com' ([Errno -2] Name or service not known)"))

The other two gives 5 lines that don't seem to succeed much either:

click to read Traceback (most recent call last): File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 366, in tapo() File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1442, in __call__ return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1363, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1226, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke return callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 294, in list_videos print('\nFound ' + str(videos['total']) + ' videos for ' + dev['alias'] + ':') ~~~~~~^^^^^^^^^ KeyError: 'total'

Proulxs avatar Jun 17 '25 20:06 Proulxs

So I tried to use https://n-use1-app-tapo-care.i.tplinknbu.com/, https://n-use1-wap-gw.i.tplinkcloud.com/ and https://n-use1-wap-gw.tplinkcloud.com/ without success.

The equivalent us-east-1 url would be https://use1-app-tapo-care.i.tplinknbu.com/ without the leading n-, I'm pretty sure. Not sure if that's going to fix your problems, though.

For the record, I successfully ran the script on Ubuntu 18.04.3 using Python 3.6.9 – might be a WSL specific problem or a problem introduced in newer Python versions?

The two other URLs are probably valid services and return a response that doesn't have the same schema the intended endpoint returns (hence you get a KeyError: 'total' (expected from videos['total']).

audeck avatar Jun 18 '25 11:06 audeck

That did it. I almost forgot to chmod +x tapo-cli.py before running the code and had gotten the 5 line error again.

I got the script running and downloading! Thank you alot for your help. The only (small) issue I have is when I answer Path that I want it on /mnt/c/MyFolder/tapo-cli/ThisFolder I get the 5 line error again... so I'm letting it download to ~$ then I use mv to move the folder from WSL into /mnt/c to bring it back on the Windows folders

Thank you alot of your help!

Proulxs avatar Jun 18 '25 12:06 Proulxs

:/ As soon as I try to put more than 1 day it break down again with the same error lines. Tried putting back the old starttime/endtime code see if that would fix it but I still get the error and only bring back the warning that this is deprecated.

(venv) adjoint@MS-1260:/mnt/c/simonp/tapo-cli$ python3 tapo-cli.py download-videos Last X days [1]: 2 Path [~/]: Overwrite [0]: /mnt/c/simonp/tapo-cli/tapo-cli.py:318: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC). end_time = datetime.datetime.utcfromtimestamp(end_unixtime).strftime('%Y-%m-%d 00:00:00') /mnt/c/simonp/tapo-cli/tapo-cli.py:319: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC). start_time = datetime.datetime.utcfromtimestamp(start_unixtime).strftime('%Y-%m-%d 00:00:00') Traceback (most recent call last): File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 366, in tapo() File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1442, in call return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1363, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1830, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 1226, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke return callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/simonp/tapo-cli/tapo-cli.py", line 326, in download_videos print('\nFound ' + str(videos['total']) + ' videos for ' + dev['alias'] + ':') ~~~~~~^^^^^^^^^ KeyError: 'total'

EDIT: Seems like the camera is making about 1'000 video per day and that's hitting some limit. So I have started editing the script to download a day at once by changing the end_unixtime so that even if I say 1 day it's actually not Today+Yesterday but rather say 3 days ago. Then I change for 4 days ago, etc. So I'm downloading a day at a time this way until I hit the earliest I have footage then I'll simply run it daily to extract videos I need until this project is done.

Proulxs avatar Jun 18 '25 13:06 Proulxs

Hi could you please shqre the script i need it urgently @Proulxs

Alex-VOIP avatar Oct 04 '25 08:10 Alex-VOIP

Hi could you please shqre the script i need it urgently @Proulxs

When you "git clone https://github.com/dimme/tapo-cli.git" it will download the script and many other required files. Sadly there is not alot of shortcut you can take.

Proulxs avatar Oct 04 '25 11:10 Proulxs