NX shortest path

Hi,
I am trying to find the shortest route between two locations using the nx.shortest_path function. In addition to the start and destination, weight should also be taken into account.

My command looks like this:

route_nodes = nx.shortest_path(G_proj, orig_node, dest_node, weight=edge_weight)

And the edge_weight function starts like this:

def edge_weight(u, v, data):
    # Länge der Kante (Standardwert = 1, falls nicht vorhanden)
    L = data.get("length", 1)

In edge_weight, however, data does not contain any information about length or speed. Although these are still present in G_proj.
Does anyone know why?

Thank you!

okay, thanks to Copilot. He suggested another solution that now works.

for u, v, data in G_proj.edges(data=True):
      data["weight"] = edge_weight(u, v, data)

# Berechne den kürzesten Pfad unter Verwendung der angepassten Kantengewichtungsfunktion
route_nodes = nx.shortest_path(G_proj, orig_node, dest_node, weight="weight")