Giter Site home page Giter Site logo

pytapo's Introduction

PyTapo

Python library for communication with Tapo Cameras

Install:

python3 -m pip install pytapo

Usage examples:

Initiate library:

from pytapo import Tapo

user = "" # user you set in Advanced Settings -> Camera Account
password = "" # password you set in Advanced Settings -> Camera Account
host = "" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())

Authentication

Depending on your camera model and firmware version, the authentication method varies.

Normally you should be able to authenticate using the "camera account" created via the Tapo App (Settings > Advanced settings > Camera account).

In case of a similar stack trace:

Traceback (most recent call last):
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 41, in __init__
    self.basicInfo = self.getBasicInfo()
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 232, in getBasicInfo
    return self.performRequest(
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 95, in performRequest
    self.ensureAuthenticated()
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 61, in ensureAuthenticated
    return self.refreshStok()
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 80, in refreshStok
    raise Exception("Invalid authentication data")
Exception: Invalid authentication data

Attempt to authenticate using admin as user and your TP-Link cloud account password as password.

Downloading Recordings

Integration supports downloading recordings saved on camera's SD card.

See example script. You need to call it with following ENV values:

  • HOST: IP Address of your camera
  • PASSWORD_CLOUD: Tapo cloud account password, it is required to access the recordings, everything is still local
  • OUTPUT: Directory where you wish to save all the recordings
  • DATE: Date for which to download recordings in format of YYYYMMDD, for example 20230221.

You also need to have ffmpeg installed as that is used for converting the streams to watchable file.

Contributions:

Contributions to pytapo are welcomed.

By creating a PR you acknowledge and agree that you are not breaking any TOS, law and/or have a permission to provide and share the code changes.

Owner of this repository is not legally responsible for any PRs or code changes to this project created by 3rd parties.

When you make a new change to the code base, make sure to have 100% unit test coverage, see below for more information about tests.

Test instructions

Set the following environment variables:

PYTAPO_USER - user you set in Advanced Settings -> Camera Account

PYTAPO_PASSWORD - password you set in Advanced Settings -> Camera Account

PYTAPO_IP - ip of the camera, example: 192.168.1.52

Install pre-commit and tox from pip.

Run pre-commit install and pre-commit install -t pre-push.

Then run tox to run all the tests.

Linters are ran on every commit.

Tests are ran on push.

Your camera may do all the actions supported by this library, including, but not limited to, move, change privacy mode and reboot while tests are running. Camera does not format SD card during tests.

After the tests are done, your camera should be in the initial state.

Thank you

Disclaimer

Pytapo is an unofficial module for achieving interoperability with Tapo cameras.

Author is in no way affiliated with Tp-Link or Tapo.

All the api requests used within the library are available and published on the internet (examples linked above) and this module is purely just a wrapper around those https requests.

Author does not guarantee functionality of this library and is not responsible for any damage.

All product names, trademarks and registered trademarks in this repository, are property of their respective owners.

pytapo's People

Contributors

aandi avatar andrempo avatar depau avatar fabaff avatar fightforlife avatar iamatulsingh avatar jurajnyiri avatar liamjack avatar luskaner avatar marcosngomezi avatar rioriost avatar sonic74 avatar tasssinclair avatar vitorsemeano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytapo's Issues

Add provisioning methods

I'm currently struggling with process of provisioning the Tapo C100 camera.

When camera is in factory state it sets the unprotected AP named Tapo_Camera_XXXX where XXXX is some hex value. After connecting the dhcp server on camera assign the 192.168.191.100 ip address, while reporting the gateway to be 192.168.191.1.

I assume it hosts the same API which is partially implemented in this library, as when querying the https server on this address it returns very similar responses.

Calling the login no matter the params, returns some stok result:

~> curl -d '{"method": "login", "params":{}}' https://192.168.191.1/ -k
{"error_code": 0, "result" : { "stok": "829dd315d803fee540f127ad0e86f54c", "user_group": "root"}}⏎ 

I found out that there should be something like onboarding module, witch scan, connect and get_connect_status.

By comparing this to other methods implemented in this library, I assume it should be called somehow like:

~> curl -d '{"method": "do", "onboarding":{"scan":{}}}' https://192.168.191.1/stok=829dd315d803fee540f127ad0e86f54c/ds -k
{ "error_code": -40106 }⏎ 

Sadly this seems not to work.

Sadly I got stuck at this point, If you got any suggestions or question please ask.

I'll try to push it somehow forward and extend this library with provisioning methods.

moveMotorStep and angle

The Tapo C200 accepts both horizontal and vertical angle as this picture shows. The moveMotorStep function accepts only a single value of angle (0-360), how can i position the camera at a particular horizontal/vertical angle?

tapo

Update time

Hi,

to enhance the privacy of the camera I've disabled its Internet access capabilities through a firewall rule on my router.

Now I've noticed that the camera seems very bad at keeping the current time, in two weeks its already off by half a day.

So it would be good to have functionality to update the time on the camera/setting the appropriate NTP servers.

If I have time I will take a look to see if that's possible somehow.

Thanks,
Moritz

Login error

Using the example code with camera C320WS:

from pytapo import Tapo

user = "[email protected]" # user you set in Advanced Settings -> Camera Account
password = "passWord" # password you set in Advanced Settings -> Camera Account
host = "192.168.9.102" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())

File "C:\Python311\Lib\site-packages\pytapo\_ init _.py", line 88, in refreshStok
raise Exception("Invalid authentication data")
Exception: Invalid authentication data

Does camera C320WS have a different authentication scheme?
The camera works ok with the TP-Link app!

Add ability to send audio to camera

I started experimenting with sending audio to the camera, ideally in the future to start use it as media_player device in Home Assistant, basically having ability to play any mp3.

Branch talk_experiments
Test file:

from pytapo import Tapo
import json
import asyncio
import logging

logging.basicConfig(level=logging.DEBUG)
# change variables here
host = ""  # change to camera IP
user = ""  # your username
password = ""  # your password
password_cloud = ""  # set to your cloud password

tapo = Tapo(host, user, password, password_cloud)

devID = tapo.getBasicInfo()["device_info"]["basic_info"]["dev_id"]


async def download_async():
    print("Starting...")
    mediaSession = tapo.getMediaSession()
    async with mediaSession:
        payload2 = {
            "params": {"talk": {"deviceId": devID, "mode": "aec"}, "method": "get"},
            "type": "request",
        }

        payload = json.dumps(payload2)
        output = b""
        dataChunks = 0

        print("Opened session")
        async for resp in mediaSession.transceive(payload):
            if resp.mimetype == "video/mp2t":
                # if len(resp.plaintext) != 376:
                dataChunks += 1
            else:
                # print(resp.plaintext)
                pass

            # if dataChunks > 2000:
            #    break

        fileName = "./output/stream.ts"
        print("Saving to " + fileName + "...")
        file = open(fileName, "wb")
        file.write(output)
        file.close()


loop = asyncio.get_event_loop()
loop.run_until_complete(download_async())

The main part is currently trying to open a working mp2 file, read first 1520 bytes (the same size as tapo is sending payloads in) and send it to the camera.

Unfortunately, nothing happens.

Download SD videos

Would be possible to download the contents of the SD card ? I'd like to have a script that automatically backups all cameras videos, thanks in advance.

Invalid URL

Is there another encryption scheme in TP-Link Tapo C320WS camera?

File "C:\Python311\Lib\site-packages\pytapo_init.py", line 88, in refreshStok
raise Exception("Invalid authentication data")
Exception: Invalid authentication data_

Unable to turn off Privacy mode too

Hi,

I'm using the following code :

    tapo=Tapo(host, user, password)
    tapo.setPrivacyMode(False)

And I also try the methode given in #33 but it isn't worked for me...

The activated part works as well :

tapo2.setPrivacyMode(True)

Any help ?

Thanks

Get and Set Home / Away Modes?

I can see a previous issue asking about toggling notifications, which is not possible due to being a cloud feature. The Android app also has Home / Away modes where you can set different settings for one or more cameras and it applies them to each camera individually (there's even a progress pop-up counting up until all selected devices are updated).

I have to ask even though it is 99% sure a cloud feature as well, but is it possible to get and set this from Python instead of toggling notifications directly?

I just can't believe the Tapo app still doesn't have geofencing to automate this stuff... It's literally called Home / Away Mode but doesn't actually check if you're home or away, you have to manually open the app and tap a button...

Dump entire Json data

Is there a way to get the entire JSON data?

image

I want to set simultaneous to True and adjust the motor speed.

This got me to wonder what other parameters are available for us to modify
Thanks for this amazing repo

Downloading Recordings

Why do I need the Tapo cloud account password as I don't even use that service?
Downloading from the SD card on the phone works ok.

RTP error

Hi, I tried use the DownloadRecordings.py but met with this error.
I am able to download 1 hour of recording before this error occurs.

This is the last line before the error
Downloading F:\2023-07-25 16_00_00-2023-07-25 17_44_02.mp4: 4096.14 / 6242

File "C:\Users\UserName\AppData\Local\Programs\Python\pytapo\lib\site-packages\rtp\rtp.py", line 165, in sequenceNumber
   raise ValueError("SequenceNumber must be in range 0-2**16")
ValueError: SequenceNumber must be in range 0-2**16

Post callback url or poll for motion events

Is it possible to use the library to set a motion event callback url or to poll the camera for motion events? (Ex. Like in The ONVIF standard)
I'm asking specifically for the C100 model.

Recordings download and timezones

Hello,
I tried to download recordings using script attached to repo - works well until I want to download most up to date recordings which gives me:

Converting /media/2023-05-05 12_17_28-2023-05-05 12_18_40.mp4...                    
Converting /media/2023-05-05 12_21_37-2023-05-05 12_22_55.mp4...                    
Converting /media/2023-05-05 12_23_18-2023-05-05 12_25_09.mp4...          11          
Converting /media/2023-05-05 12_25_47-2023-05-05 12_27_38.mp4...          11          
Recording in progress /media/2023-05-05 12_39_01-2023-05-05 12_40_41.mp4...          
Recording in progress /media/2023-05-05 12_43_47-2023-05-05 12_45_32.mp4...          
Recording in progress /media/2023-05-05 12_46_24-2023-05-05 12_47_40.mp4...          
Recording in progress /media/2023-05-05 12_52_02-2023-05-05 12_53_11.mp4...          
Recording in progress /media/2023-05-05 12_58_03-2023-05-05 12_59_46.mp4...          
Recording in progress /media/2023-05-05 13_03_31-2023-05-05 13_05_25.mp4...          
Recording in progress /media/2023-05-05 13_05_52-2023-05-05 13_07_18.mp4...          
Recording in progress /media/2023-05-05 13_10_05-2023-05-05 13_12_13.mp4...          
Recording in progress /media/2023-05-05 13_14_29-2023-05-05 13_15_38.mp4...          
Recording in progress /media/2023-05-05 13_19_13-2023-05-05 13_20_22.mp4...          
Recording in progress /media/2023-05-05 13_25_17-2023-05-05 13_26_26.mp4...          
bd8ebebf5524:/config/scripts# date
Fri May  5 14:32:24 CEST 2023
bd8ebebf5524:/config/scripts# date -u
Fri May  5 12:34:19 UTC 2023

Looks like timezone problem?

Notify

Is possible, or it will be possible in future to enable and disable Notifications?
I want to use tapo camera as alarm.
But i want to disable when i'm at home (and i have manually disable on all cameras when i'm at home)
Anyway very nice software thanks!

Control camera remotely

Hi,

I have a Tapo C200 that configured which DDNS and Port Forwarding, so I have no problem streaming in RTSP with VLC. However when I use the domain in host parameter (e.g. mydomain.ddns.net:554), It throw an error:

Traceback (most recent call last):
  File "c:\Users\ThoaiNguyen(Intern)\Documents\tapo_controller\testt.py", line 7, in <module>
    tapo = Tapo(host, user, password)
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\pytapo\__init__.py", line 41, in __init__
    self.basicInfo = self.getBasicInfo()
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\pytapo\__init__.py", line 232, in getBasicInfo
    return self.performRequest(
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\pytapo\__init__.py", line 95, in performRequest
    self.ensureAuthenticated()
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\pytapo\__init__.py", line 61, in ensureAuthenticated
    return self.refreshStok()
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\pytapo\__init__.py", line 74, in refreshStok
    res = requests.post(
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\requests\api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\ThoaiNguyen(Intern)\AppData\Roaming\Python\Python39\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='abcxyz.ddns.net', port=554): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)')))

How can I fix it? Thank you

Compatibility with "Tapo C325WB"

Hi there,
First of all, I want to express my heartfelt gratitude for your selfless contribution of the "pytapo" package to us.

I mainly want to inquire about the compatibility of the "pytapo" package with the latest "Tapo C325WB" camera. I am currently considering using this camera for a project.

If it's not compatible, I'd like to ask whether the "pytapo" package works with the "Tapo C320WS" or "Tapo C310" cameras.

If it is compatible, I'm curious whether the "pytapo" package supports the new AI features of the "Tapo C325WB" camera, such as obtaining detection coordinates for people and vehicles.

Your assistance is highly appreciated. Thank you!

C310

any way to use pytapo on c310?

Add patrol mode

Hi,
Thanks for your work on this library.
I'm using it with my C210 camera and I was wondering if it was possible to control the "patrol" capability.

There are two options: "Horizontal" and "Vertical".

Here's a capture of the app (In French ^^') :
image

Thanks for your response,
Maxime

moveMotor coordinate

I have a tapo C200. moveMotor( x ,y ) moves the camera when x and y are not equal to zero but does not move when both are zero.

Does it mean that 0 , 0 is the center of the screen and each movement mean that the new 0,0 is where the camera has finished moving to?

getMotorCapability() results to:

{
   "motor":{
      "capability":{
         ".name":"capability",
         ".type":"capability",
         "x_coord_max":"170",
         "x_coord_min":"-170",
         "y_coord_max":"35",
         "y_coord_min":"-35",
         "x_max_speed":"9",
         "y_max_speed":"9",
         "simultaneous":"disabled",
         "preset":"enabled",
         "calibrate":"enabled",
         "lens_mask_no_moving":"1"
      }
   },
   "error_code":0
}

moveMotor():

{'error_code': 0}
{
   "device_info":{
      "basic_info":{
         "device_type":"SMART.IPCAMERA",
         "device_model":"C200",
         "device_name":"C200 1.0",
         "device_info":"C200 1.0 IPC",
         "hw_version":"1.0",
         "sw_version":"1.1.11 Build 210625 Rel.56514n(5553)",
         "device_alias":"Tapo_Camera_71B8",
         "features":"3",
         "barcode":"",
         "mac":"xxxxxxxxxx", #hidden
         "dev_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", #hidden
         "oem_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx", #hidden
         "hw_desc":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #hidden
      }
   },
   "error_code":0
}

Get error "-60102", cannot an error code definition, and need a workaround

I have used this code successfully with a pair of Tapo C200 cameras, but then I started to get the error "-60102". As an example:

>>> tapo.setPreset(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/pytapo/__init__.py", line 847, in setPreset
    return self.executeFunction(
  File "/usr/local/lib/python3.9/dist-packages/pytapo/__init__.py", line 138, in executeFunction
    raise Exception(
Exception: Error: -60102, Response: {"method": "motorMoveToPreset", "result": {}, "error_code": -60102}

What does error code -60102 mean?

I noticed this after implementing a firewall change to block the cameras from leaving my LAN. At the same time, I saw that my firewall blocked access to at least 5 different addresses of which at least 2 were Amazon EC2 nodes. It was TCP/443 (https) and UDP/123 (NTP). And the occasional UDP/53 (DNS). I might have missed something else.

This behaviour persisted even after rebooting the cameras. After the reboot, the time was wrong,

The weird thing is that the cameras sometimes, not always (and sometimes after a long delay) actually did move as commanded. But mostly, they did not.

Any workaround to get these cameras to work better without Internet connectivity?

Also, I noticed there is a "getTime()" method but no "setTime()" method - So the NTP calls from the cameras might be the only way to update the time.


Edit: I had inadvertently allowed DNS traffic through my firewall, and that seemed to cause the timeouts and -60102 error codes. Also blocking DNS made the cameras responsive, without this error code.

The only remaining problem is that the video timestamp is wrong, since there does not seem to be any other way to set the time than to let the cameras query a public NTP server, and there is no "setTime()" method.

But the original issue is solved.


connect externally

is it possible to use pytapo to connect to tapo externally? I have received errors when trying to do this.

Downloading recordings on Windows

Hello, did anyone tried to download recordings on Windows machine? I'm getting the following error:

Downloading C:\[path]...
could not convert string to float: b''
Warning: Could not calculate length from stream.

On Ubuntu it works fine.

Repost for closing post #67

In reference of my previous #67 You might not believe but i bunched my head against Google the whole day long but without any success, it would had not be my purpose to wrote if I had found the solution.
PIP being an old version was not installed correctly could be fine, but no solution applied did solved it.
If you look for the specific error referred to MyTapo You will not find one single occurance on the Web.
If you look generally You will find a lot of occurency, but i tested all of them without any success.
Hope someone will be able to reply to this.
PS: I reopened a new post since the last one was forcibly closed by the admin.
Regards
Andrea

SetOsd broken when label string is blank

In SetOsd function, if string is blank, labelEnabled is set False, but this has no effect as the code that reads this variable occurs before.

I tried changing: labelEnabled = False to data["OSD"]["label_info_1"]["enabled"] = "off". This seems to work. Alternatively the code could be shifted about but that's more likely to break other things.

Apologies, this is my first ever Issue raise, GitHub still confuses me. I've forked the project and made the change, because I don't understand pull requests!

Unable to move motor on Tapo C210

Hi,

I'm trying to control my Tapo C210 with pytapo. Everything works fine so far, except for the motor control (pan and/or tilt).

When using

tapo = Tapo(host, user, password)
tapo.moveMotorStep(10)

I get the following traceback:

Traceback (most recent call last):
  File "/tmp/tapo/test.py", line 27, in <module>
    toggle_privacy()
  File "/tmp/tapo/test.py", line 18, in toggle_privacy
    tapo.moveMotorStep(10)
  File "/tmp/tapo/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 288, in moveMotorStep
    return self.performRequest(
  File "/tmp/tapo/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 113, in performRequest
    raise Exception(
Exception: Error: -64316 Response:{"error_code": -64316}

Thanks!
Best

Unable to turn off Privacy mode (delete please)

Im using following code:

from pytapo import Tapo

user = "xxxx" # user you set in Advanced Settings -> Camera Account
password = "xxx" # password you set in Advanced Settings -> Camera Account
host = "192.168.xxx.xxx" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getPrivacyMode())

print(tapo.setPrivacyMode('enabled'))

print(tapo.getPrivacyMode())

And this is my output:
{'.name': 'lens_mask_info', '.type': 'lens_mask_info', 'enabled': 'on'} {'result': {'responses': []}, 'error_code': 0} {'.name': 'lens_mask_info', '.type': 'lens_mask_info', 'enabled': 'on'}

It wont disable. Why?

Update: Realised I needed to leave string empty. Thought sending enabled would turn it off if it was enabled (act as switch)

print(tapo.setPrivacyMode(''))

Please delete this issue!

Successfully downloaded C420 camera recordings.

I have successfully downloaded the video recorded by the C420 via the H200 Hub.
Unfortunately, I could not achieve this with the current code as it is, and a few modifications were necessary.

Here is the code I modified.

https://github.com/GracefulTabby/pytapo
GracefulTabby@e144ae8
https://github.com/GracefulTabby/pytapo/blob/main/experiments/DownloadRecordingsViaHub.py

I am not good at writing clean code like you guys.
If possible, can someone create a pull request as a good code?

Of course, it can be used as is. I have successfully backed up my camera with this code.
I was able to work with the latest firmware.
C420 : V1.27 Build 20230426 rel.34233
H200 : 1.2.18 Build 20230510 rel.65350

I have tried the following and got to this point.
I put a proxy (mitmproxy) between the iPhone and the H200 and monitored between port 443 and port 8800.

Basically, everything is communicated through the Hub, specifying the ChildID to the Hub.
To get a list of recorded videos, the C420 seemed to use searchVideoWithUTC and searchDetectionList while other cameras seemed to use searchVideoOfDay.
I have made sure to use getRecordingsUTC when C420 is used for the camera.
Also, when retrieving the stream, it seems necessary to give a query parameter instead of a POST parameter.
Something called PlayerID also needs to be included in the query parameter or header, but this was a constant value when communicating between the iPhone and H200.
It is probably the UUID assigned to the Tapo account.
For some reason, this PlayerID also worked with a randomly generated UUID. There does not appear to be any particular check.

This is as far as I was able to go with my capabilities.

Strange Issue: Stok Error with VPN Enabled

I am having a strange issue where I get a stok error whenever my VPN is enabled?

Exception: Error: Invalid stok value, Response: {"error_code": -40401, "result": {"data": {"code": -40407, "encrypt_type": ["1", "2"], "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7QdgMKoS6Gl0oq4TLfeldgM6%2fikwuuS8fp0RzNVpPD9CrxRzL3X3%2f4WD0sji33NQOuk59ZSZprgHw6x9%2bEEpjDXGDDLZvba%2bsQ5jk%2f2uBxyKTUjM8jtzr%2fK9I79uTGxSWK7Hlh4gb6kwBXdN%2bqdy0uTdZPn1cWCVqAf5%2fJHmx9wIDAQAB", "nonce": "lU3L7xDN"}}

Same code works fine without vpn.


user = "User" # user you set in Advanced Settings -> Camera Account
password = "password" # password you set in Advanced Settings -> Camera Account
host = "some remote wan ip" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

Fresh installation of Python 3.9.9 not allowing installation of pytapo

Hi there,
I just updated my Python release to 3.9.9
I am continuously having the issue about trying to install Pytapo as follow here below.
Not sure if the red error is a consequence of the previous warning, but could possibly be.
Any idea how to solve it without having to use the old version?
I did not found any limit on the Meta tag of the pytapo page, so I suppose it shall work with no issue with my release.

Thanks for your effort,

Andrew

pi@raspberrypi:~ $ python -m pip install pytapo
Defaulting to user installation because normal site-packages is not writeable
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
Could not fetch URL https://pypi.org/simple/pytapo/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pytapo/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pytapo/
Could not fetch URL https://www.piwheels.org/simple/pytapo/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='www.piwheels.org', port=443): Max retries exceeded with url: /simple/pytapo/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement pytapo (from versions: none)
ERROR: No matching distribution found for pytapo
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not fetch URL https://www.piwheels.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='www.piwheels.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

requests.exceptions.SSLError

I'm having an issue connecting to the camera.

Everything works fine on the app and I can stream the video with VLC and ping the IP. My credentials are correct and I've tried both my mail and admin

from pytapo import Tapo

user = "admin" # user you set in Advanced Settings -> Camera Account
password = "my_passowrd" # password you set in Advanced Settings -> Camera Account
host = "10.10.96.28" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())

I'm having requests.exceptions.SSLError: HTTPSConnectionPool(host='10.10.96.28', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)')))

I have 2FA ON, could it be the issue?

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

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'))

http status 401 with DownloadRecordings.py

Hi,

I'm using a C200 camera and trying to download recordnings from the SD card.
I get this error below when i run the script.

Traceback (most recent call last): File "/home/ophenix/DownloadRecordings.py", line 100, in <module> loop.run_until_complete(download_async()) File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/ophenix/DownloadRecordings.py", line 81, in download_async async for status in downloader.download(): File "/home/ophenix/.venv/lib/python3.11/site-packages/pytapo/media_stream/downloader.py", line 115, in download async with mediaSession: File "/home/ophenix/.venv/lib/python3.11/site-packages/pytapo/media_stream/session.py", line 74, in __aenter__ await self.start() File "/home/ophenix/.venv/lib/python3.11/site-packages/pytapo/media_stream/session.py", line 156, in start raise HttpStatusCodeException(status_code) pytapo.media_stream.error.HttpStatusCodeException: HTTP request returned 401 status code

So it seems there's something wrong with the cloud authentication.

I have tried several ways, adjusting the variables with the camera password and the cloud password. When I test with print(tapo.getBasicInfo()), I get information from the camera, so at least that works. However, I still can't download any video from it.

Any ideas?

Is it possible to use this library to get the camera image?

Currently, I am using RTSP protocol to get images (png) (using opencv) from tapo cameras.

However, RTSP protocol somehow provides not good enough image resolution. (Not sure why)

So, is there a way (using this library) to get camera "printscreens" with better resolution?

Add more request for states ?

Is it possible to add requests for states ?
like :
getPosition() wich return x and y coordonates
getNightMode() wich return True if night mode is enable
getMotionState() wich return True if the motion sensors is trigered

thanks

Can't connect to camera

While trying to use the library (a simple tapo.getBasicInfo() ), I get this:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.100.34', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000158CD2B3DC0>: Failed to establish a new connection

Camera has the latest firmware 1.1.8 build 210425 rel.66776n(4555) . I can see the rtsp with no issues using cv2, so ports are working, I guess.

Support for motion detection triggered

I've got a C110 that i want to query and check if it is currently detecting motion, but that doesn't seem to be supported. Is there a way to do this, even if it is manually doing it rather than using pytapo?

Set time/date

As titles says. Is their any way to change date and time of tapo cameras. Im blocking my cameras from internet and only using them via HomeKit intergration (Scrypted) but when doing this the camera date is always 2021-12-02. I guess it's because blocking internet access block any NTP server cameras are using. So any way to set NTP server or add date manually?

SetSystemDateAndTime

I am using a C310 without HA. I managed to do settings via pytapo and reading events through onvif-zeep-async (see https://github.com/pablo-zarate/Tapo-C200-event-listener).
However I am not able to manage SetSystemDateAndTime via onvif. I tried the onvif-zeep-async and onvif-zeep with python3 and onvif with python2. In python3 I am stuck with errors on wsdl and xml. In pyhton2 I end up with
onvif.exceptions.ONVIFError: Type not found: 'tt:AutoRebootSupport'

Is there any support on setting the time through pytapo or any recommendation for a simple onvif library or commandline tool to do the job?

Add download/upload conf support

When I was looking at uhttpd and dsd, I realized there are two URLs : "/admin/system/download_conf" and ""/admin/system/download_conf"". Also there are two functions named download_conf and upload_conf in uhttpd, with some obvious DES encryption.
圖片

Unfortunately I'm super bad at tracing and reconstructing code for now so I have no idea how this API should look like. So I'm hoping the great reverse engineers here can take a look and see if it's possible to implement in pytapo :)

Camera doesn't auto track target no more

Hey, the auto track target function was working greatly with very high accuracy. But since the new update (1.1.7) it doesn't do that anymore and the camera stays still unless I move it.

Error Code -71112 on download of recordings

I can contact the camera through python and successfully run:
tapo = Tapo(host, user, password)
print(tapo.getBasicInfo())

Now trying to download content from the SD card. There are three videos and one still picture on the SD card which I can download through the phone app.
However I get this error when executing the example code to fetch content from the SD card:
File "C:\Python311\Lib\site-packages\pytapo_init_.py", line 138, in executeFunction
raise Exception(
Exception: Error: -71112, Response: {"method": "searchVideoOfDay", "result": {}, "error_code": -71112}

Googled without success for python error -71112. What does this error mean?

download still images?

Is there a way to download a still image from the C210?
The best I've found so far is this:

ffmpeg -y -i rtsp://USER:PASS@camera:554/stream1 -vframes 1 test.jpg

that works, but often ends up with corrupted jpg. Most cameras like this have some URL for still images but I haven't found one yet for the CP210. Anyone know of one?

Examples to use pytapo

Hi @JurajNyiri!

Can you please add some examples to use the implementation ?

I could make the tapo.calibrateMotor() and unable to view the video stream in python,

best
Shanmuga

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.