dse graph python - No such property: g for class: error - python

I am new to dse graph. I am getting an error
No such property: g for class: error
what could I be doing wrong?
>>> from dse.cluster import Cluster, EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT, GraphExecutionProfile
>>> from dse.graph import GraphOptions
>>> from dse.auth import PlainTextAuthProvider
>>> Auth_provider = PlainTextAuthProvider(username=<<username>>,
password=<<password>>)
>>> ep = GraphExecutionProfile(graph_options=GraphOptions(graph_name='idg'))
>>> cluster = Cluster(database_cluster, auth_provider=auth_provider,
execution_profiles={EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT: ep})
>>> dse_session.execute_graph('g.V()')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dse/cluster.py", line 2017, in dse.cluster.Session.execute_graph
File "dse/cluster.py", line 3962, in dse.cluster.ResponseFuture.result
dse.InvalidRequest: Error from server: code=2200 [Invalid query] message="No such property: g for class: Script184"
>>> print(vars(ep.graph_options))
{'_graph_options': {'graph-name': b'idg', 'graph-source': b'g', 'graph-language': b'gremlin-groovy', 'graph-results': b'graphson-1.0'}}

Instead of the EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT when defining execution profile you need to use EXEC_PROFILE_GRAPH_DEFAULT. The EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT is used to access to System API to manipulate graphs, etc.
You also need to connect to cluster via session = cluster.connect() (I don't see it in your code).
See driver docs for more examples.

Works now. After I used EXEC_PROFILE_GRAPH_DEFAULT for the execution profile
>>> from dse.cluster import Cluster, EXEC_PROFILE_GRAPH_DEFAULT, GraphExecutionProfile
>>> from dse.graph import GraphOptions,SimpleGraphStatement
>>> from dse.auth import PlainTextAuthProvider
>>> Auth_provider = PlainTextAuthProvider(<<username>>, <<password>>)
>>> ep = GraphExecutionProfile(graph_options=GraphOptions(graph_name='idg'))
>>> cluster = Cluster(database_cluster, auth_provider=auth_provider, execution_profiles={EXEC_PROFILE_GRAPH_DEFAULT: ep})
>>> dse_session = cluster.connect()
>>> dse_session.execute_graph('g.V()')
<dse.cluster.ResultSet object at 0x10f1fbef0>

Related

return empty result via using Entrez,Efetch to search lineage from taxonomy db

I used biopython to search lineage information from taxonomy database, but it returns empty !
I can used it yesterday(2016/3/15) ! But now I can't used it(2016/03/16)!
The code I used is here,
>>> from Bio import Entrez
>>> Entrez.email = "myemail#gmail.com"
>>> handle = Entrez.esearch(db="Taxonomy", term="Cypripedioideae")
>>> record = Entrez.read(handle)
>>> record["IdList"]
['158330']
>>> record["IdList"][0]
'158330'
>>> handle = Entrez.efetch(db="Taxonomy", id="158330", retmode="xml")
>>> records = Entrez.read(handle)
>>> records[0].keys()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> records
[] #I can't understand why it returns empty today?

TypeNotFound error in Suds Soap library

I'm trying to call a SOAP service from the Dutch land register (WSDL here) with the suds library. I first introspect the SOAPservice as follows:
>>> from suds.client import Client
>>> client = Client(url='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl')
>>> print client
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
Service ( VerzoekTotInformatieService ) tns="http://www.kadaster.nl/schemas/kik-inzage/20141101"
Prefixes (13)
ns0 = "http://www.kadaster.nl/schemas/kik-inzage/20141101"
...
ns9 = "http://www.kadaster.nl/schemas/kik-inzage/kadastraalberichtobject/v20141101"
Ports (1):
(VerzoekTotInformatieSOAP)
Methods (1):
VerzoekTotInformatie(ns3:Aanvraag Aanvraag, ) # <== WE WANT TO CALL THIS
Types (278):
ns10:AN1
ns10:AN10
...
ns3:Aanvraag # <== FOR WHICH WE NEED THIS TYPE
ns10:AlgemeenAfsluiting
ns10:AlgemeenBegin
...
So I want to call the (only available) method VerzoekTotInformatie (which means "RequestForInformation") which takes an Aanvraag object ("Aanvraag" means "Request"). As you can see the Aanvraag type is in the list of Types. So I tried creating it as suggested in the docs, using:
>>> Aanvraag = client.factory.create('Aanvraag')
No handlers could be found for logger "suds.resolver"
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Library/Python/2.7/site-packages/suds/client.py", line 234, in create
raise TypeNotFound(name)
TypeNotFound: Type not found: 'Aanvraag'
>>>
Does anybody know why the type is not found, even though it is clearly displayed in the list of types?
All tips are welcome!
You need to add the prefix:
In [9]: Aanvraag = client.factory.create('ns3:Aanvraag')
In [10]: Aanvraag
Out[10]:
(Aanvraag){
berichtversie =
(VersieAanvraagbericht){
value = None
}
klantReferentie = None
productAanduiding = None
Gebruiker =
(Gebruiker){
identificatie = None
}
Ingang = <empty>
}

How do I clear a Python threading.local object?

How can I clear all the attributes off an instance of Python's threading.local()?
You can clear it's underlying __dict__:
>>> l = threading.local()
>>> l
<thread._local object at 0x7fe8d5af5fb0>
>>> l.ok = "yes"
>>> l.__dict__
{'ok': 'yes'}
>>> l.__dict__.clear()
>>> l.__dict__
{}
>>> l.ok
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'thread._local' object has no attribute 'ok'
Accessing the __dict__ directly is specifically called out as a valid way to interact with the local object in the _threading_local module documentation:
Thread-local objects support the management of thread-local data.
If you have data that you want to be local to a thread, simply create
a thread-local object and use its attributes:
>>> mydata = local()
>>> mydata.number = 42
>>> mydata.number
42
You can also access the local-object's dictionary:
>>> mydata.__dict__
{'number': 42}
>>> mydata.__dict__.setdefault('widgets', [])
[]
>>> mydata.widgets
[]

Python object validation thanks to a Schema

I want to validate a python object thanks to a schema. For this I found the schema framework.
I would like to validate a numeric string:
a = {
'phone_number': '12233'
}
Do you know how can I validate this string thanks to a regex?
At this time, I only know how to perform a string validation:
Schema(str).validate('12')
Schema will call any callables; simply provide a function that uses a regular expression:
import re
pattern = re.compile('^12\d+$')
Schema(And(str, lambda x: pattern.match(x) is not None))
Demo:
>>> import re
>>> from schema import Schema, And
>>> pattern = re.compile('^12\d+$')
>>> s = Schema(And(str, lambda x: pattern.match(x) is not None))
>>> s.validate('123234')
'123234'
>>> s.validate('42')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/schema.py", line 153, in validate
raise SchemaError([None] + x.autos, [e] + x.errors)
schema.SchemaError: <lambda>('42') should evaluate to True

Gremlin / Bulbflow: how to get an integer result out of execute()

Sorry if this question is too stupid to ask... I am a newbie on Python+Django+Bulbs+Neo4j.
I am attempting --without success-- to get an integer produced by g.gremlin.execute() while using Python+Django shell, as detailed below.
First, the query in Neo4j's Gremlin console:
gremlin> g.v(2).out
==> v[6]
==> v[4]
==> v[8]
==> v[7]
gremlin> g.v(2).out.count()
==> 4
What I intend to do it to get this result in Python+Django shell, passing it to a variable, as tried below:
>>> from bulbs.neo4jserver import Graph
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> sc = " g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> val = g.gremlin.execute(sc,params)
>>> val
<bulbs.neo4jserver.client.Neo4jResponse object at 0x243cfd0>
I can't get any further from now on.
>>> val.one()
<bulbs.neo4jserver.client.Neo4jResult object at 0x2446b90>
>>> val.one().data
>>> val.one().results
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Neo4jResult' object has no attribute 'results'
Could anyone please tell me what am I doing wrong?
Many thanks!
Raw result data is going to be in the Result object's raw attribute:
>>> from bulbs.neo4jserver import Graph
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> script = " g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> resp = g.gremlin.execute(script,params)
>>> result = resp.one()
>>> result.raw
NOTE: result.data returns an element's property data, so it will be empty unless you are returning a vertex or edge, i.e. a node or relationship in Neo4j parlance.
See...
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L60
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L88
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L167
To see what Neo4j Server returned in the server response, you can output the Response headers and content:
>>> from bulbs.neo4jserver import Graph
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> script = "g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> resp = g.gremlin.execute(script,params)
>>> resp.headers
>>> resp.content
And if you set the loglevel to DEBUG in Config, you'll be able to see what's being sent to the server on each request. When DEBUG is enabled, Bulbs also sets the raw attribute on the Response object (not to be confused with the raw attribute that is always set on the Result object). Response.raw will contain the raw server response:
>>> from bulbs.neo4jserver import Graph, DEBUG
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> g.config.set_logger(DEBUG)
>>> script = " g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> resp = g.gremlin.execute(script,params)
>>> resp.raw
See...
https://github.com/espeed/bulbs/blob/master/bulbs/config.py#L70
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L221
http://bulbflow.com/quickstart/#enable-debugging
To turn off DEBUG, set the loglevel back to ERROR:
>>> from bulbs.neo4jserver import ERROR
>>> g.config.set_logger(ERROR)
See...
http://bulbflow.com/quickstart/#disable-debugging

Categories

Resources