mit TR-64 API die Anruferliste mit einem Pythonscript auslesen klappt nicht

StefanL38

New member
Hallo Fritzbox-Experten,

ich probiere mit einem Pythonscript über die TR-64 Schnittstelle die Anruferliste auszulesen.
Das Script schreibt alles mögliche in eine Logdatei. Meine Vermutung aber nicht wissen ist, dass der Aufruf zum Abruf der URL in der dann die Anruferliste drinsteht
nicht mit Port 80 sondern auch mit Port 49000 gemacht werden muss.

Wirklich wissen tue ich es nicht. Und ich wüsste auch nicht was ich im Code ändern müsste um den Port auf 49000 zu ändern.
Bei meiner Internetrecherche habe ich nur uralt Artikel (2013 ) dazu gefunden.

Kennt jemand ein funktionierendes Script das mit aktuellem FritzOS 8.03 funktioniert?
Kann mir jemand sagen was ich an meinem Pythonscript ändern müsste um es ans laufen zu bringen?

Hier ist die Ausgabe aus der Logdatei:
Code:
2025-08-08 09:49:11 - INFO - === Script Start ===
2025-08-08 09:49:11 - DEBUG - Starting new HTTP connection (1): 192.168.178.1:49000
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /igddesc.xml HTTP/1.1" 200 3475
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /tr64desc.xml HTTP/1.1" 200 13825
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /any.xml HTTP/1.1" 200 293
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /igdicfgSCPD.xml HTTP/1.1" 200 9433
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /igddslSCPD.xml HTTP/1.1" 200 4130
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /igdconnSCPD.xml HTTP/1.1" 200 14813
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /igd2ipv6fwcSCPD.xml HTTP/1.1" 200 5426
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /deviceinfoSCPD.xml HTTP/1.1" 200 4339
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /deviceconfigSCPD.xml HTTP/1.1" 200 5864
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /layer3forwardingSCPD.xml HTTP/1.1" 200 7947
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /lanconfigsecuritySCPD.xml HTTP/1.1" 200 3975
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /mgmsrvSCPD.xml HTTP/1.1" 200 6016
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /timeSCPD.xml HTTP/1.1" 200 2863
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /userifSCPD.xml HTTP/1.1" 200 9657
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_storageSCPD.xml HTTP/1.1" 200 4580
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_webdavSCPD.xml HTTP/1.1" 200 2047
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_upnpSCPD.xml HTTP/1.1" 200 1150
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_speedtestSCPD.xml HTTP/1.1" 200 4861
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_remoteSCPD.xml HTTP/1.1" 200 6804
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_myfritzSCPD.xml HTTP/1.1" 200 7583
2025-08-08 09:49:11 - DEBUG - http://192.168.178.1:49000 "GET /x_voipSCPD.xml HTTP/1.1" 200 35952
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_contactSCPD.xml HTTP/1.1" 200 18626
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_dectSCPD.xml HTTP/1.1" 200 4101
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_tamSCPD.xml HTTP/1.1" 200 5229
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_appsetupSCPD.xml HTTP/1.1" 200 22136
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_homeautoSCPD.xml HTTP/1.1" 200 16925
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_homeplugSCPD.xml HTTP/1.1" 200 3479
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_filelinksSCPD.xml HTTP/1.1" 200 6210
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_authSCPD.xml HTTP/1.1" 200 1805
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_hostfilterSCPD.xml HTTP/1.1" 200 2463
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_mediaSCPD.xml HTTP/1.1" 200 2751
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /x_uspcontrollerSCPD.xml HTTP/1.1" 200 14995
2025-08-08 09:49:12 - DEBUG - http://192.168.178.1:49000 "GET /wlanconfigSCPD.xml HTTP/1.1" 200 33192
2025-08-08 09:49:13 - DEBUG - http://192.168.178.1:49000 "GET /wlanconfigSCPD.xml HTTP/1.1" 200 33192
2025-08-08 09:49:14 - DEBUG - http://192.168.178.1:49000 "GET /wlanconfigSCPD.xml HTTP/1.1" 200 33192
2025-08-08 09:49:15 - DEBUG - http://192.168.178.1:49000 "GET /hostsSCPD.xml HTTP/1.1" 200 15594
2025-08-08 09:49:15 - DEBUG - http://192.168.178.1:49000 "GET /ethifconfigSCPD.xml HTTP/1.1" 200 2848
2025-08-08 09:49:15 - DEBUG - http://192.168.178.1:49000 "GET /lanhostconfigmgmSCPD.xml HTTP/1.1" 200 6255
2025-08-08 09:49:15 - DEBUG - http://192.168.178.1:49000 "GET /wancommonifconfigSCPD.xml HTTP/1.1" 200 8556
2025-08-08 09:49:15 - DEBUG - http://192.168.178.1:49000 "GET /x_wanmobileconnSCPD.xml HTTP/1.1" 200 12633
2025-08-08 09:49:15 - DEBUG - http://192.168.178.1:49000 "GET /wanethlinkconfigSCPD.xml HTTP/1.1" 200 548
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:49000 "GET /wanpppconnSCPD.xml HTTP/1.1" 200 21580
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:49000 "GET /wanipconnSCPD.xml HTTP/1.1" 200 15086
2025-08-08 09:49:16 - DEBUG - [get_call_list] FritzConnection Adresse: Unbekannt, Port: Unbekannt
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:49000 "POST /upnp/control/x_contact HTTP/1.1" 401 170
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:49000 "POST /upnp/control/x_contact HTTP/1.1" 200 374
2025-08-08 09:49:16 - DEBUG - API Response GetCallList: {'NewCallListURL': 'http://192.168.178.1:49000/calllist.lua?sid=3298cd430082fcd7'}
2025-08-08 09:49:16 - INFO - Anrufliste wird von URL geladen: http://192.168.178.1:49000/calllist.lua?sid=3298cd430082fcd7
2025-08-08 09:49:16 - DEBUG - [fetch_calllist_from_url_via_fc] FritzConnection verwendet Host: Unbekannt, Port: Unbekannt
2025-08-08 09:49:16 - DEBUG - Pfad: calllist.lua, Query-Parameter: {'sid': '3298cd430082fcd7'}
2025-08-08 09:49:16 - DEBUG - Starting new HTTP connection (1): 192.168.178.1:80
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:80 "GET /login_sid.lua?version=2 HTTP/1.1" 200 None
2025-08-08 09:49:16 - DEBUG - Resetting dropped connection: 192.168.178.1
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:80 "POST /login_sid.lua?version=2 HTTP/1.1" 200 None
2025-08-08 09:49:16 - DEBUG - Resetting dropped connection: 192.168.178.1
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:80 "GET /webservices/homeautoswitch.lua?switchcmd=calllist.lua&ain=sid&sid=484d18a907e4e2f9 HTTP/1.1" 400 0
2025-08-08 09:49:16 - DEBUG - Resetting dropped connection: 192.168.178.1
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:80 "GET /login_sid.lua?version=2 HTTP/1.1" 200 None
2025-08-08 09:49:16 - DEBUG - Resetting dropped connection: 192.168.178.1
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:80 "POST /login_sid.lua?version=2 HTTP/1.1" 200 None
2025-08-08 09:49:16 - DEBUG - Resetting dropped connection: 192.168.178.1
2025-08-08 09:49:16 - DEBUG - http://192.168.178.1:80 "GET /webservices/homeautoswitch.lua?switchcmd=calllist.lua&ain=sid&sid=c58ba5ae2bd05a34 HTTP/1.1" 400 0
2025-08-08 09:49:16 - ERROR - Fehler beim Abrufen der Anrufliste von URL über FritzConnection: Request failed: http error code '400', payload: {'switchcmd': 'calllist.lua', 'ain': {'sid': '3298cd430082fcd7'}, 'sid': 'c58ba5ae2bd05a34'}
2025-08-08 09:49:16 - ERROR - Anrufliste aus der Fritzbox auslesen fehlgeschlagen: Leere oder keine Antwort von der CallList URL
2025-08-08 09:49:16 - INFO - === Script Ende wegen leerer Anrufliste ===

Das Pythonscript verursachte den Fehler mehr als 10000 Zeichen.
Versuche es als TXT anzuhängen

Hier links zur Doku der TR-64-API
TR-64 API Übersicht
Erste Schritte
 

Anhänge

  • Fritzbox-TR-64-API-Anruferliste-auslesen-013.txt
    6,4 KB · Aufrufe: 1
Moin,

also ich habe weder was mit Programmierung noch groß mit Fritz!Boxen zu tun und mit dem Thema des gleich folgenden Links auch nix (ist hier nur öfters mal Thema), aber vielleicht hilft es ja, wenn man sich mal anschaut, wie andere es so machen.

Dazu einmal folgendes:
https://www.home-assistant.io/integrations/fritz/#prerequisites
Ist ein/e Addon/Integration für HomeAssistant (Smarthome-Management), womit man auch div. Dinge aus der Fritz!Box auslesen kann. Der o.g. Link zeigt allerdings schon auf einen bestimmten Teil, welcher die Notwendigen Vorbereitungen für den Zugriff aufzeigt. Vielleicht hilft Dir das ja schon. Ansonsten hier nochmal die Github-Seite dazu, Code ist auch Python - vielleicht einfach mal durchschauen :)
 
Hallo,

Vielen Dank für eure Antworten.
Ich habe inzwischen das hier gefunden
https://administrator.de/tutorial/p...tzwerk-konfigurieren-und-auslesen-303474.html
Zitat:
Ich hatte dazu zwar schon einen Artikel für die Bash geschrieben, jedoch hat dieser das ganze Prozedere über das Webinterface realisiert was jedoch durch die ständigen Anpassungen seitens AVM nicht für dauerhafte Skripte geeignet und auch nicht sehr zuverlässig ist wenn zukünftige Updates auf der FritzBox gefahren werden.

Also habe ich das ganze nun mal mit der standardisierte Schnittstelle TR-064 umgesetzt welche die Fritzbox unterstützt. Die Abfragen laufen dort über standardisierte SOAP-Requests auf die uPnP Schnittstelle der Box (Port 49000/49443) ab.
Darauf basierend habe ich es dann hinbekommen
Das ganze dient am Ende dazu unerwünschte Nummern ein ein Fritzbox Telefonbuch "gesperrte Nummern" einzutragen.
Der erste Schritt dazu ist eine Whitelist Funktion
Es ist eine Rufbehandlung eingerichtet die alle Anrufe ohne Telefonnummer und alle Anrufe von Telefonnummern die NICHT im Telefonbuch (= der Whitelist stehen) auf einen Anrufbeantworter umleitet der den Anrufer informiert

"du bist nicht im Telefonbuch wenn du ein seriöses Anliegen hast sprich eine Nachricht auf Band"

Das gibt dann in der Fritzbox Telefonliste einen Eintrag mit "AB Für unbekannte Anrufer"

Das Pythonscript liest das Fritzbox-Telefonbuch ein und trägt die Nummern mit "AB Für unbekannte Anrufer" in eine Textdatei ein.

Was jetzt noch nicht programmiert ist, ist das automatisierte Eintragen dieser Nummern in das Telefonbuch "gesperrte Nummern"
Wenn sie dort eingetragen sind dann wird der Anruf von diesen Nummern komplett abgeblockt.

Und wie immer hat das Programm zu viele Zeichen und passt nicht direkt hier rein.
 

Anhänge

  • Fritzbox-TR-64-SOAP-Anruferliste-auslesen-ohne-PW.txt
    8,1 KB · Aufrufe: 0
Ohne Gewähr:

Python:
import requests
import xml.etree.ElementTree as ET

# Fritz!Box-Zugangsdaten
fritzbox_ip = "192.168.178.1"  #  IP-Adresse der Fritz!Box
username = "your_username"
password = "your_password"

# Funktion zur Anmeldung und Datenabruf
def get_call_list(fritzbox_ip, username, password):
    try:
        # Anmeldung
        session = requests.Session()
        response = session.get(f"http://{fritzbox_ip}/login_sid.lua?version=2&username={username}&response={password}", verify=False)
        sid = ET.fromstring(response.content).findtext("SID")

        # Anrufliste abrufen
        response = session.get(f"http://{fritzbox_ip}/data.lua?sid={sid}&page=calllist&xhr=1", verify=False)
        data = response.json()

        # Daten verarbeiten und ausgeben
        if data and data.get("data"):
           for entry in data["data"]:
              print(f"Zeit: {entry.get('time')}, Nummer: {entry.get('number')}, Name: {entry.get('name')}")


    except Exception as e:
        print(f"Fehler: {e}")

# Aufruf der Funktion
get_call_list(fritzbox_ip, username, password)
 
Ohne Gewähr:

Python:
import requests
import xml.etree.ElementTree as ET

# Fritz!Box-Zugangsdaten
fritzbox_ip = "192.168.178.1"  #  IP-Adresse der Fritz!Box
username = "your_username"
password = "your_password"

# Funktion zur Anmeldung und Datenabruf
def get_call_list(fritzbox_ip, username, password):
    try:
        # Anmeldung
        session = requests.Session()
        response = session.get(f"http://{fritzbox_ip}/login_sid.lua?version=2&username={username}&response={password}", verify=False)
        sid = ET.fromstring(response.content).findtext("SID")

        # Anrufliste abrufen
        response = session.get(f"http://{fritzbox_ip}/data.lua?sid={sid}&page=calllist&xhr=1", verify=False)
        data = response.json()

        # Daten verarbeiten und ausgeben
        if data and data.get("data"):
           for entry in data["data"]:
              print(f"Zeit: {entry.get('time')}, Nummer: {entry.get('number')}, Name: {entry.get('name')}")


    except Exception as e:
        print(f"Fehler: {e}")

# Aufruf der Funktion
get_call_list(fritzbox_ip, username, password)
Is ne nette Lösung (hab ich nicht gestetet) über die GUI auszulesen ist aber auch lange Sicht nicht so sicher wie über die API zu gehen. Ich würde daher die API bevorzugen.
 
So vielleicht (ohne Gewähr)?
Python:
import requests
import xml.etree.ElementTree as ET

# Fritzbox API URL
fritzbox_url = "http://fritz.box:49000"

# TR-064 SOAP Action für die Anrufliste
action = "urn:dslforum-org:service:X_AVM-DE_OnTel:1#GetCallList"

# SOAP-Header
headers = {
    "Content-Type": "text/xml; charset=utf-8",
    "SOAPAction": action,
}

# SOAP-Body
body = f"""<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <soap:Body>
    <GetCallList xmlns="urn:dslforum-org:service:X_AVM-DE_OnTel:1">
    </GetCallList>
  </soap:Body>
</soap:Envelope>"""

try:
    # Senden der Anfrage
    response = requests.post(fritzbox_url, headers=headers, data=body)
    response.raise_for_status()  # Fehlerprüfung

    # Verarbeitung der Antwort
    root = ET.fromstring(response.content)
    call_list = root.find('.//{urn:dslforum-org:service:X_AVM-DE_OnTel:1}NewCallList')

    if call_list is not None:
        for call in call_list.findall('{urn:dslforum-org:service:X_AVM-DE_OnTel:1}Call'):
            calldate = call.find('{urn:dslforum-org:service:X_AVM-DE_OnTel:1}CallDate').text
            calltime = call.find('{urn:dslforum-org:service:X_AVM-DE_OnTel:1}CallTime').text
            number = call.find('{urn:dslforum-org:service:X_AVM-DE_OnTel:1}Number').text
            name = call.find('{urn:dslforum-org:service:X_AVM-DE_OnTel:1}Name').text
            type_ = call.find('{urn:dslforum-org:service:X_AVM-DE_OnTel:1}Type').text # In- oder Outgoing

            print(f"Datum: {calldate}, Zeit: {calltime}, Nummer: {number}, Name: {name}, Typ: {type_}")
    else:
        print("Keine Anrufe gefunden.")

except requests.exceptions.RequestException as e:
    print(f"Fehler bei der Anfrage: {e}")
except ET.ParseError as e:
    print(f"Fehler beim Parsen der XML-Antwort: {e}")
 
Wenn Du Home Assistant hast: Es gibt eine Integration "Fritzbox Call Monitor". Da ist alles fertig.
 

Zurzeit aktive Besucher

Letzte Anleitungen

Statistik des Forums

Themen
6.959
Beiträge
67.629
Mitglieder
7.335
Neuestes Mitglied
HeXor
Zurück
Oben