It's hard to tell from your code fragments.
If you ask for the degree of a node that doesn't exist in the graph you will get an error (not a random value).
>>> import networkx as nx
>>> G = nx.Graph()
>>> nx.degree(G,0)
'int' object is not iterableTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nh/nest/u/aric/.local/lib/python2.7/site-packages/networkx/classes/function.py", line 53, in degree
return G.degree(nbunch,weight)
File "/nh/nest/u/aric/.local/lib/python2.7/site-packages/networkx/classes/graph.py", line 1248, in degree
return dict(self.degree_iter(nbunch,weight))
File "/nh/nest/u/aric/.local/lib/python2.7/site-packages/networkx/classes/graph.py", line 1291, in degree_iter
for n,nbrs in nodes_nbrs:
File "/nh/nest/u/aric/.local/lib/python2.7/site-packages/networkx/classes/graph.py", line 1288, in <genexpr>
nodes_nbrs=((n,self.adj[n]) for n in self.nbunch_iter(nbunch))
File "/nh/nest/u/aric/.local/lib/python2.7/site-packages/networkx/classes/graph.py", line 1808, in bunch_iter
"nbunch is not a node or a sequence of nodes.")
networkx.exception.NetworkXError: nbunch is not a node or a sequence of nodes.