I think the trouble is not nodes with degree zero (they would not be a common neighbor if the degree is zero).
The only time we divide by zero is if log(degree(w)) is zero. That means degree(w) is 1.
How can a node be a common neighbor if degree is 1?
I suspect you're running into self-loops. Furthermore you are saying that node1 and node2 are really the same node. So that indicates self-loops will be popping up. Almost certainly using the same number to represent 2 nodes is causing confusion in the graph structure,
Each node should compare as not equal to other nodes. The graph structure is dict-of-dict-of-dict, so the node needs to act as a unique key to the dictionary keyed by node to neighbors. Said another way, your two nodes that are both 100 are being treated as a single node. Then you look for common neighbors of a node (100) and itself. Apparently there is only 1 neighbor of 100... itself.
Maybe you should be storing 100 as an attribute of the nodes instead of having 100 act as the node itself.