Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use Console: AttributeError: 'str' object has no attribute 'decode #43

Open
riogrande75 opened this issue Nov 24, 2024 · 4 comments

Comments

@riogrande75
Copy link

riogrande75 commented Nov 24, 2024

Trying to run DahuaConsole on a Debian12.8 system with python3.11.
Console seems to be able to login as usual, but unfortunately as soon as I issue a command it crashes:

root@ldap:/etc/DahuaConsole# /etc/DahuaConsole/bin/python3 Console.py --rhost 192.168.1.35 --rport 5000 --auth admin:passw --proto dhip
[*] [Dahua Debug Console 2019-2021 bashis <mcw noemail eu>]
[*] logon type "default" with proto "dhip" at 192.168.1.35:5000
[+] Opening connection to 192.168.1.35 on port 5000: Done
[+] Dahua Debug Console: Success
[+] Login: Success
[+] keepAlive thread: Started
[*] [Active Users]
    [email protected] since 2024-11-24 10:30:01 with "Console" (Id: 21)
[*] Remote Model: VTH5221D, Class: VTH, Time: 2024-11-24 10:30:01
[Console]# config all
Traceback (most recent call last):
  File "/etc/DahuaConsole/Console.py", line 888, in <module>
    main()
  File "/etc/DahuaConsole/Console.py", line 882, in main
    DebugConsole(dargs=dargs)
  File "/etc/DahuaConsole/Console.py", line 32, in __init__
    self.main_console()
  File "/etc/DahuaConsole/Console.py", line 223, in main_console
    msg = sys.stdin.readline().strip().decode('ascii')
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'decode'
[*] Closed connection to 192.168.1.35 port 5000
root@ldap:/etc/DahuaConsole#


Any idea why this happens?

BTW: Using Console to e.g. dump config with parameter "--dump config" works fine.

@zyuganlee
Copy link

deleting .strip().decode('ascii') entirely works for me

@riogrande75
Copy link
Author

riogrande75 commented Nov 25, 2024

Thx. As I am not a python guy I just followed strictly what you suggested:

             #msg = sys.stdin.readline().strip().decode('ascii')
             msg = sys.stdin.readline()

But this leads to following error msg:

  File "/etc/DahuaConsole/Console.py", line 224
    msg = sys.stdin.readline()
                              ^
IndentationError: unindent does not match any outer indentation level

@zyuganlee
Copy link

check if there is extra space or tab beside the .readline()

or try replace your code with this, see if it helps

try:
self.prompt()
#msg = sys.stdin.readline().strip().decode('ascii')
msg = sys.stdin.readline()
if not self.dh or not self.dh.remote.connected():
log.failure('No available instance')
return False
cmd = msg.split()

i have python 3.12.3

@riogrande75
Copy link
Author

Thx - my fault: Do not use tab's with python code...
It works again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants