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
Related
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>
I'm new to python and xml-rpc , and I'm stuck with decoding binary data coming from a public service :
the service request response with this code is :
from xmlrpc.client import Server
import xmlrpc.client
from pprint import pprint
DEV_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
logFile = open('stat.txt', 'w')
s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.GetStatPassaggi(token)
pprint(res, logFile)
response :
{'id_richiesta': '257a369dbf46e41ba275f8c821c7e1e0',
'risposta': {'periodi_aggregazione': <xmlrpc.client.Binary object at 0x0000027B7D6E2588>,
'tempi_attesa_percorsi': <xmlrpc.client.Binary object at 0x0000027B7D9276D8>}}
I need to decode these two binary objects , and I'm stuck with this code :
from xmlrpc.client import Server
import xmlrpc.client
from pprint import pprint
DEV_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx'
logFile = open('stat.txt', 'w')
s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.GetStatPassaggi(token)
dat = xmlrpc.client.Binary(res)
out = xmlrpc.client.Binary.decode(dat)
pprint(out, logFile)
that ends in :
Traceback (most recent call last): File "stat.py", line 18, in
dat = xmlrpc.client.Binary(res) File "C:\Users\Leonardo\AppData\Local\Programs\Python\Python35\lib\xmlrpc\client.py",
line 389, in init
data.class.name) TypeError: expected bytes or bytearray, not dict
The only doc I found for xmlrpc.client is the one at docs.python.org , but I can't figure out how I could decode these binaries
If the content of res variable (what you get from the 2nd (s2) server) is the response you pasted into the question, then you should modify the last 3 lines of your 2nd snippet to (as you already have 2 Binary objects in the res dictionary):
# ... Existing code
res = s2.paline.GetStatPassaggi(token)
answer = res.get("risposta", dict())
aggregation_periods = answer.get("periodi_aggregazione", xmlrpc.client.Binary())
timeout_paths = answer.get("tempi_attesa_percorsi", xmlrpc.client.Binary())
print(aggregation_periods.data)
print(timeout_paths.data)
Notes:
According to [Python.Docs]: xmlrpc.client - Binary Objects (emphasis is mine):
Binary objects have the following methods, supported mainly for internal use by the marshalling/unmarshalling code:
I wasn't able to connect (and this test the solution), since DEV_KEY is (obviously) fake
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?
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 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
[]