JurajNyiri / pytapo

Python library for communication with Tapo Cameras
MIT License
277 stars 58 forks source link

unable to get it working with tapo c220 camera #107

Closed alessiozanutta closed 5 months ago

alessiozanutta commented 5 months ago

I am writing to seek assistance with pytapo since I've encountered an issue while trying to connect my Tapo C220 camera to my MacBook to download the saved recordings through DownloadRecordings.py. I am facing an error when attempting to execute the code in PyCHARM with the installed pytapo 3.3.19 package. The error message is as follows:

self.hashedPassword = hashlib.md5(password.encode("utf8")).hexdigest().upper()
AttributeError: 'NoneType' object has no attribute 'encode'

I have tried using both my username and "admin" as credentials, as you have suggested in the README. Additionally, I have set the following environment variables in the DownloadRecordings.py file:

# mandatory
outputDir = os.environ.get("/Users/mymacusername/Documents")  # directory path where videos will be saved
date = os.environ.get("20240330")  # date to download recordings for in format YYYYMMDD
host = os.environ.get("10.0.1.144")  # change to camera IP
password_cloud = os.environ.get("password")  # set to your cloud password

Despite these settings, the error persists and, also attempting to run the simpler:

from pytapo import Tapo

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

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())

returns an error on both username conditions (admin or myusername):

Traceback (most recent call last):
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/test-aza.py", line 7, in <module>
    tapo = Tapo(host, user, password)
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 86, in __init__
    self.basicInfo = self.getBasicInfo()
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 1009, in getBasicInfo
    return self.executeFunction(
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 491, in executeFunction
    data = self.performRequest(
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 530, in performRequest
    self.ensureAuthenticated()
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 108, in ensureAuthenticated
    return self.refreshStok()
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 418, in refreshStok
    return self.refreshStok(loginRetryCount)
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 418, in refreshStok
    return self.refreshStok(loginRetryCount)
  File "/Users/alessiozanutta/PycharmProjects/pythonProject/.venv/lib/python3.9/site-packages/pytapo/__init__.py", line 423, in refreshStok
    raise Exception("Invalid authentication data")
Exception: Invalid authentication data

Could you please guide me on what might be going wrong? Any help you can provide would be greatly appreciated.

NOTE: in Frigate I am able to get videos using the following:

cameras:
  tapo_cam_c220: # <------ Name the camera
    onvif:
      host: 10.0.1.144
      port: 2020
      user: username
      password: password

Thank you for your time and assistance.

JurajNyiri commented 5 months ago

Hi the first error with none - your environment value is not properly loaded.

for the second error try using ‘admin’ and your TP-Link cloud password.

JurajNyiri commented 5 months ago

Additionally your output dir value as well as host and date from os environ is probably wrong

JurajNyiri commented 5 months ago

Hardcode everything at first and when it works try with the os environment values etc to rule out mistakes

alessiozanutta commented 5 months ago

Thank you Juraj, I have already tried ADMIN as written above with no luck. What do you mean HARDCODE?

JurajNyiri commented 5 months ago

IMG_0332 You are using actual values inside os.environ. Put them directly as a string. Admin with TP-Link cloud password not rtsp password.

alessiozanutta commented 5 months ago

thank you for spotting this, however I'm having no luck in downloading correctly the recordings. Even if now I am able to connect to the camera with:

# mandatory
outputDir = "/Users/alessiozanutta/Documents/"  # directory path where videos will be saved
date = "20240330"  # date to download recordings for in format YYYYMMDD
host = "10.0.1.144"  # change to camera IP
password_cloud = "cloud-password"  # set to your cloud password

# optional
window_size = "50" # set to prefferred window size, affects download speed and stability, recommended: 50

print("Connecting to camera...")
tapo = Tapo(host, "admin", password_cloud, password_cloud)

NOTE-1: the error was using the camera-account password and not the tapo app password (namely the password of the account)

I am not able to download all the files in the SD card.

The ERROR-outcome is now:

could not convert string to float: b'N/A\n'
Warning: Could not calculate length from stream.

Server did not send a new chunk in 10.0 sec (sequence 5105, session 45), assuming the stream is over
Server did not send a new chunk in 10.0 sec (sequence 23088, session 46), assuming the stream is over
Giving up /Users/alessiozanutta/Documents/2024-03-31 14_04_38-2024-03-31 14_09_25.mp4...  

do you know what could be the cause or where I can retrieve a log or something with more informations on the error?

JurajNyiri commented 5 months ago

Make sure you have ffmpeg dependencies installed

alessiozanutta commented 5 months ago

Thank you! all settled after having installed ffmpeg into the VENV used to run the script (previously I had installed ffmpeg only system-wide).

However sometimes I still got

could not convert string to float: b'N/A\n' Warning: Could not calculate length from stream.

on some files. How should I check to have ALL the ffmpeg dependencies installed? is there a list of packages that I should force to install?

JurajNyiri commented 5 months ago

You need ffmpeg and ffprobe.

alessiozanutta commented 5 months ago

checked an it's all fine with the dependencies. still...

Connecting to camera...
Getting recordings...

could not convert string to float: b'N/A\n'
Warning: Could not calculate length from stream.

could not convert string to float: b'N/A\n'
Warning: Could not calculate length from stream.
Downloading /Volumes/SMB_some-video-recordings/20240331/2024-03-31 14_02_13-2024-03-31 14_03_49.mp4...          
could not convert string to float: b'N/A\n'
Warning: Could not calculate length from stream.