kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
304 stars 59 forks source link

Error message when access is done with wrong password #12

Closed SmartC2016 closed 4 years ago

SmartC2016 commented 4 years ago

When I try:

fc = fritzconnection.FritzConnection(address='192.168.90.1', password='wrong_password')
fc.call_action('WLANConfiguration', 'GetInfo')

I get a trace back error:


 /home/heti/Development/fritzconnection/fritzconnection/core/soaper.py(53)raise_fritzconnection_error()
-> root = etree.fromstring(response.content)
(Pdb) l
 48         Will raise a FritzConnectionException or a subclass.
 49         """
 50         parts = []
 51         error_code = None
 52         import pdb;pdb.set_trace()
 53  ->     root = etree.fromstring(response.content)
 54         detail = root.find('.//detail')
 55         for node in detail.iterdescendants():
 56             tag = node.tag.split('}')[-1]
 57             text = node.text.strip()
 58             if tag == 'errorCode':
(Pdb) p response.content
b'<HTML><HEAD><TITLE>401 Unauthorized (ERR_NONE)</TITLE></HEAD><BODY><H1>401 Unauthorized</H1><BR>ERR_NONE<HR><B>Webserver</B> Sun, 17 Nov 2019 10:17:47 GMT</BODY></HTML>\r\n'
(Pdb) c

Traceback (most recent call last):

File "/home/heti/.local/share/virtualenvs/fritzconnection-ehIjW6m7/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-5-5cee539ecdc0>", line 1, in <module>
    fc.call_action('WLANConfiguration', 'GetInfo')

  File "/home/heti/Development/fritzconnection/fritzconnection/core/fritzconnection.py", line 124, in call_action
    return self.soaper.execute(service, action_name, arguments)

  File "/home/heti/Development/fritzconnection/fritzconnection/core/soaper.py", line 140, in execute
    raise_fritzconnection_error(response)

  File "/home/heti/Development/fritzconnection/fritzconnection/core/soaper.py", line 53, in raise_fritzconnection_error
    root = etree.fromstring(response.content)

  File "src/lxml/etree.pyx", line 3222, in lxml.etree.fromstring

  File "src/lxml/parser.pxi", line 1877, in lxml.etree._parseMemoryDocument

  File "src/lxml/parser.pxi", line 1765, in lxml.etree._parseDoc

  File "src/lxml/parser.pxi", line 1127, in lxml.etree._BaseParser._parseDoc

  File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc

  File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult

  File "src/lxml/parser.pxi", line 640, in lxml.etree._raiseParseError

  File "<string>", line 1
XMLSyntaxError: Opening and ending tag mismatch: HR line 1 and BODY, line 1, column 162
kbr commented 4 years ago

Will check this next weekend when I have access to the hardware.

Themanwithoutaplan commented 4 years ago

I can't replicate that error on the 1.0 branch but I do have trouble connecting even with the correct password from the CLI

fritzconnection charlieclark$ fritzconnection -i fritz.box -p pw

FritzConnection v1.0a1
Traceback (most recent call last):
  File "/Users/charlieclark/Projects/fritzconnection/bin/fritzconnection", line 11, in <module>
    load_entry_point('fritzconnection', 'console_scripts', 'fritzconnection')()
  File "/Users/charlieclark/Projects/fritzconnection/fritzconnection/cli/fritzinspection.py", line 139, in main
    inspector.view_header()
  File "/Users/charlieclark/Projects/fritzconnection/fritzconnection/cli/fritzinspection.py", line 35, in view_header
    print(self.fc)
  File "/Users/charlieclark/Projects/fritzconnection/fritzconnection/core/fritzconnection.py", line 77, in __repr__
    return f'{self.device_manager.modelname} at ip {self.soaper.address}'
  File "/Users/charlieclark/Projects/fritzconnection/fritzconnection/core/devices.py", line 33, in modelname
    return self.descriptions[0].device_model_name
IndexError: list index out of range
Themanwithoutaplan commented 4 years ago

On the same system, in Python itself I can usually connect but get a different exception.

fc.call_action('WLANConfiguration1', 'GetInfo')
Traceback (most recent call last):
  Python Shell, prompt 7, line 121
builtins.KeyError: 'WLANConfiguration1'

During handling of the above exception, another exception was raised:

Traceback (most recent call last):
  Python Shell, prompt 7, line 1
    # Used internally for debug sandbox under external interpreter
  File "/Users/charlieclark/Projects/fritzconnection/fritzconnection/core/fritzconnection.py", line 123, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WLANConfiguration1"
kbr commented 4 years ago

Seems the box is unable to read the description files. May be a side effect of removing lxml. I can go to this by end of the week. Sorry, no sooner. Should set up a VPN then.

kbr commented 4 years ago

I suppose I found it – at least in theory: the documentation of DeviceManager.add_description is misleading. The parameter source is not the xml-source but the url where to retrieve the source from the box. lxml can handle this, but ElementTree from the stdlib can't. So this should be fixed in __init__ of FritzConnection to send the sources to add_description and not the url.

This and Christians topic are two different issues.

Themanwithoutaplan commented 4 years ago

Agreed. I think there are two separate additional issues: the transient one relating to model name (I've had this in the CLI and in the Python shell) and the service description thingy. I'll create some tickets and see if I can run some low level tests for more meaningful data. @SmartC2016 can you add the model number to your description?

kbr commented 4 years ago

There have been some subtle issues left in error raising. Is fixed now by 21499f7ec68cc5ec0268cccd5088e83569edbd0f