Im still trying to make a social network with py2neo+flask+neo4j.
I've got a problem while searching my database with py2neo.I wanna find all the users that their username includes a special string.For example all the users that their username includes "dav".I wrote the code below and i dont know why i get this error...
from py2neo import Graph
graph=Graph("http://neo4j:123#localhost:7474/ ")
def search(name):
users=graph.merge("Person")
for N in users:
print N['username']
and this is my error:
Traceback (most recent call last):
File "", line 1, in
File "/home/ali/Desktop/flask/search.py", line 10, in search users=graph.cypher.execute('match (p:Person) return p'
File "/usr/local/lib/python2.7/dist-packages/py2neo/core.py", line 659, in cypher metadata = self.resource.metadata
File "/usr/local/lib/python2.7/dist-packages/py2neo/core.py", line 213, in metadata self.get()
File "/usr/local/lib/python2.7/dist-packages/py2neo/core.py", line 267, in get raise_from(self.error_class(message, **content), error)
File "/usr/local/lib/python2.7/dist-packages/py2neo/util.py", line 235, in raise_from raise exception py2neo.error.GraphError: HTTP GET returned response 404
Your URL is wrong, you should change it to this:
Graph("http://neo4j:123#localhost:7474/db/data")
Also, you can't execute cypher through the merge function, instead you should do this:
users = graph.cypher.execute('match (p:Person) return p')
Related
I used to be able to use secretmanager to get secrets from my GCP account using google collab.
Now, whenever I try to run the following code:
client = secretmanager.SecretManagerServiceClient()
name = f"projects/my_project_here/secrets/my_secret_name_here/versions/latest"
response = client.access_secret_version(request={"name": name})
I get the following error over and over:
ERROR:grpc._plugin_wrapping:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x7fb313b41850>" raised exception!
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/google/auth/compute_engine/credentials.py", line 111, in refresh
self._retrieve_info(request)
File "/usr/local/lib/python3.7/dist-packages/google/auth/compute_engine/credentials.py", line 88, in _retrieve_info
request, service_account=self._service_account_email
File "/usr/local/lib/python3.7/dist-packages/google/auth/compute_engine/_metadata.py", line 234, in get_service_account_info
return get(request, path, params={"recursive": "true"})
File "/usr/local/lib/python3.7/dist-packages/google/auth/compute_engine/_metadata.py", line 187, in get
response,
google.auth.exceptions.TransportError: ("Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Enginemetadata service. Status: 404 Response:\nb''", <google.auth.transport.requests._Response object at 0x7fb313b9c290>)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/grpc/_plugin_wrapping.py", line 90, in __call__
context, _AuthMetadataPluginCallback(callback_state, callback))
File "/usr/local/lib/python3.7/dist-packages/google/auth/transport/grpc.py", line 101, in __call__
callback(self._get_authorization_headers(context), None)
File "/usr/local/lib/python3.7/dist-packages/google/auth/transport/grpc.py", line 88, in _get_authorization_headers
self._request, context.method_name, context.service_url, headers
File "/usr/local/lib/python3.7/dist-packages/google/auth/credentials.py", line 133, in before_request
self.refresh(request)
File "/usr/local/lib/python3.7/dist-packages/google/auth/compute_engine/credentials.py", line 117, in refresh
six.raise_from(new_exc, caught_exc)
File "<string>", line 3, in raise_from
google.auth.exceptions.RefreshError: ("Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Enginemetadata service. Status: 404 Response:\nb''", <google.auth.transport.requests._Response object at 0x7fb313b9c290>)
How can I see what user I am in google collab and then add this user in GCP so I can again fetch these secrets?
I know to go to GCP->Secret Manager->My_Secret->Permissions->+Grant Access, but I don't know how to know 1) Who to Add 2) Why this permission changed on its own with no intervention on anyone's end.
Both were originally running under my email (and they are still) so this worked without me ever having to touch secrets access because both were the App Engine default service account<->Secret Manager Secret Accessor
How to get testplanid in testlink project? I have given name 'myTestProjectTestBuild' to my test plan, but while giving this name as testplanid, it says The Test Plan ID (0) provided does not exist!
>>> tls.getBuildsForTestPlan('myTestProjectTestBuild')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/testlink/testlinkdecorators.py", line 140, in wrapperReplaceTLResponseError
response = methodAPI(self, *argsPositional, **argsOptional)
File "/usr/lib/python2.7/site-packages/testlink/testlinkdecorators.py", line 112, in wrapperAddDevKey
return methodAPI(self, *argsPositional, **argsOptional)
File "/usr/lib/python2.7/site-packages/testlink/testlinkdecorators.py", line 100, in wrapperWithArgs
*argsPositional, **argsOptional)
File "/usr/lib/python2.7/site-packages/testlink/testlinkapigeneric.py", line 1515, in callServerWithPosArgs
self._checkResponse(response, methodNameAPI, argsOptional)
File "/usr/lib/python2.7/site-packages/testlink/testlinkapigeneric.py", line 1879, in _checkResponse
response[0]['message'], response[0]['code'])
testlink.testlinkerrors.TLResponseError: 3000: (getBuildsForTestPlan) - The Test Plan ID (0) provided does not exist!
getBuildsForTestPlan({'testplanid': 'myTestProjectTestBuild', 'devKey': 'xyz'})
Can someone let me know from where I can get testplanid in testlink?
I got the value of testplanid with tls.getProjectTestPlans('<project_id').
After login, you will get a test plan management link, click it then hover over the test plan that you want to get its Id. At the bottom you will see tplan_id = some number. That is the test plan ID
I am having trouble trying to perform flask-restless api queries on data that is contained inside a JSONB object. I'm going to guess it's because the underlying query doesn't know how to cast the data field so it doesn't know how to generate the query properly, but I'm not sure.
The query that is run when I perform an ajax search:
http://192.168.163.129:1080/api/subscribers?page=1&results_per_page=10&q={"filters":[{"name":"data","op":"has","val":{"name":"full_name","op":"eq","val":"%Steve%"}}],"order_by":[{"field":"created","direction":"asc"}]}
This is the traceback I get when I run the query.
2016-12-29 22:26:33,068 - app - ERROR - mapper
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask_restless/views.py", line 1172, in _search
result = search(self.session, self.model, search_params)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 587, in search
query = create_query(session, model, search_params, _ignore_order_by)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 549, in create_query
_ignore_order_by)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 480, in create_query
filters = [create_filt(model, filt) for filt in search_params.filters]
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 438, in _create_filter
return create_op(model, fname, filt.operator, val, relation)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 411, in _create_operation
return opfunc(field, argument, fieldname)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 106, in <lambda>
'has': lambda f, a, fn: f.has(_sub_operator(f, a, fn)),
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 37, in _sub_operator
submodel = model.property.mapper.class_
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 833, in __getattr__
return self._fallback_getattr(key)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 811, in _fallback_getattr
raise AttributeError(key)
AttributeError: mapper
API Code:
manager.create_api(Subscribers, methods=['GET'], results_per_page=10,
preprocessors=dict(GET_SINGLE=[subscribers_preprocessor],
GET_MANY=[subscribers_preprocessor]))
The pre-processor is a simple authentication processor.
Any idea how to properly format a filter for filtering on JSONB postgres fields?
The answer at this point is, you can't with flask-restless as is.
I did some modification to flask-restless to split a specially formatted query string and cast the query correctly for jsonb. Kind of a pain, and probably not scalable.
It is marked for enhancement on flask-restless git.
https://github.com/jfinkels/flask-restless/issues/623
I have the following celery task:
#task
def get_users_facebook_as_profile_icon(user_id, facebook_id):
logger.info('Grabbing users facebook picture')
url = "http://graph.facebook.com/%s/picture?type=large" % facebook_id
import requests
response = requests.get(url)
if response.status_code != 200:
raise Exception("Could not get facebook profile picture")
...
I have more after this, but I keep getting the following error:
"AssertionError('PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()',)"
Task was called with args: (3246, 17500596) kwargs: {}.
The contents of the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 437, in __protected_call__
return self.run(*args, **kwargs)
File "/home/ubuntu/mounzawebsite/mounza/celery_tasks/login_registration.py", line 42, in get_users_facebook_as_profile_icon
hashname = user.generate_picture_name()
File "/home/ubuntu/mounzawebsite/mounza/web/models.py", line 515, in generate_picture_name
return generate_random_name(None)
File "/home/ubuntu/mounzawebsite/mounza/web/models.py", line 40, in generate_random_name
str(random.randint(1, 99982098098908237)) +
File "/usr/lib/python2.7/dist-packages/Crypto/Random/__init__.py", line 41, in get_random_bytes
return _UserFriendlyRNG.get_random_bytes(n)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 213, in get_random_bytes
return _get_singleton().read(n)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 163, in read
return _UserFriendlyRNG.read(self, bytes)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 122, in read
self._check_pid()
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 138, in _check_pid
raise AssertionError("PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()")
AssertionError: PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()
I tried digging into this online, not able to find the root cause. but this is the only task where this error occurs. The only difference is that i'm downloading an image from Facebook, but I never see this issue anywhere else, including other tasks where I download images.
The URL works perfectly if I do it through a web browser, but it's only via this task it fails. Is there anything else that could contribute to this??
I have exhausted all attempts in fixing this :(
Here is why:
http://comments.gmane.org/gmane.comp.python.amqp.celery.user/3664
always run teh below:
Crypto.Random.atfork()
When a new worker process is initialized. Done and done.
I was using Apache Solr for quite some time and only recently started running into some severe issues with it. I'm using it with haystack and a django project. When I do it from manage.py shell i'm getting the below:
>>> from haystack.query import SearchQuerySet
>>> emps = SearchQuerySet().filter(django_ct='web.employer').filter(name__icontains='Mi')[:10]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/haystack/query.py", line 241, in __getitem__
self._fill_cache(start, bound)
File "/usr/local/lib/python2.7/dist-packages/haystack/query.py", line 140, in _fill_cache
results = self.query.get_results(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 469, in get_results
self.run(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/solr_backend.py", line 501, in run
results = self.backend.search(final_query, **search_kwargs)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 47, in wrapper
return func(obj, query_string, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/solr_backend.py", line 202, in search
raw_results = self.conn.search(query_string, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 578, in search
response = self._select(params)
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 308, in _select
return self._send_request('get', path)
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 293, in _send_request
error_message = self._extract_error(resp)
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 372, in _extract_error
reason, full_html = self._scrape_response(resp.headers, resp.content)
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 404, in _scrape_response
p_nodes = body_node.cssselect('p')
AttributeError: 'NoneType' object has no attribute 'cssselect'
I tried reinstalling haystack, lxml, cssselect, pysolr and still i'm getting these errors. Is there anything else I can try for this? Thanks for any help!
I also tried reading few other SO questions including this:
XML error object has no attribute 'cssselect'
Seems like the issue is with pysolr. You might find some help here.
I had the same issue persist even after bringing up pysolr and lxml to latest version.
Turned out it was because I was not using haystack generated schema which has a few additional fields compared to the default solr one.
You can confirm if this is the case by looking at your solr logs.
It is an issue with pysolr. It hasn't been fixed till 3.3.0.
The only alternative would be to override the pysolr code and make adjustments for when Solr returns a reponse status!=200.
You can check if the response has body attribute or not and make adjustments according to that.