If we check what type of object is G.nodes[node]
we can see this is a dictionary.
type(G.nodes[node])
# result <class 'dict'>
When you try to access an un-existing key in a dictionary you get this error. check out this question I'm getting Key error in python.
You have two ways to handle this:
import networkx as nx
G = nx.Graph()
G.add_node("firstNode")
# option 1
for node in G.nodes:
node_dict = G.nodes[node]
if node_dict.get('size') is None:
node_dict['size']=35
# option 2
for node in G.nodes:
node_dict = G.nodes[node]
if 'size' not in node_dict or node_dict['size'] is None:
node_dict['size']=35