Py2neo error “AttributeError: 'NoneType' object has no attribute 'graph' ”

I keep getting error from Py2neo: "AttributeError: 'NoneType' object has no attribute 'graph'" when I am trying to create some relations. The weird part is that when I run all lines through the python console - they all complete successfully.
My code (all parameters are strings from HTML forms):

service = Node("service", name=service_name, type=type, features=features_all, options=options_all, qualities=qualities_all, aspects=aspects_all)
    service_domain = Relationship(service, "ARRANGED_BY", selecteddomain)
    service_platform = Relationship(service, "PART_OF", selectedplatform)

Exactly the same error I was getting when I was executing the following queries, instead of using the Nodematcher:

domain_query = "MATCH (d:domain) WHERE d.domainname={selected_domain} RETURN d"
selecteddomain = graph.evaluate(domain_query, {"selected_domain": selected_domain})
platform_query = "MATCH (p:platform) WHERE p.platformname={selected_platform} RETURN p"
selectedplatform = graph.evaluate(platform_query, {"selected_platform": selected_platform})

Now - the problem only exists when the selected_platform is made of more than one word in the string. On the selected domain part the problem doesn't exist.

Again - when I try all these on the Python console - they work fine, and the nodes and relations are created.

Difficult to say exactly what's going wrong without more of your code available, but I had the same error this morning. 'NoneType' object has no attribute 'graph' - you're trying to access "graph" on a NoneType object, i.e. before you get this error, instead of getting a node back, you're getting None.

In my case, I was using matcher.match and it wasn't finding a node match. Try printing out selectedplatform - you should see that it's None.

Then check whether the parameters you're passing into matcher.match actually match the node you created.