How to remotely access an neo4j community container running on azure with python(neo4j module)?
There is a neo4j community version container running on the azure, and i was provided by the dns
http://[remote-address]:7687
if i do curl with proxy(px from github)(office recommended also), i able to get, bolt_routing, transaction, bolt_direct, neo4j_version, neo4j_edition all successfully,
And with 7474 port with web browser i also able to connect to the db and same with neo4j desktop by adding remote db.
but when i do with python neo4j driver, Cannot resolve address [remote-address]:7687
import neo4j,sys
link = "bolt://" + sys.argv[1]
print(f"Trying to connect to: {link}")
def exp():
try:
x = neo4j.GraphDatabase.driver(link, auth=("neo4j", "my_pswd"))
print(x.verify_connectivity())
except Exception as e:
print(e)
so, how to connect to a container hosted on azure ?
Update:
i tried to connect with IP of the azure instance running, but
Couldn't connect to [IP-address]:7687 (resolved to ('[IP-address]:7687',)):
Failed to establish connection to ResolvedIPv4Address(('[IP-address]', 7687)) (reason [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)
it is connection through web and neo4j browser completely fine, only not through the python script.!!
2 answers
-
answered 2022-03-18 00:17
jose_bacoy
I would recommend neo4j Aura. It is a fully managed cloud service and has a hassle free connection to a database. It is also has a free tier to try. See sample script to connect into it:
import neo4j,sys link = "bolt://" + sys.argv[1] print(f"Trying to connect to: {link}") #format of uri is <9999>.databases.neo4j.io def exp(): try: x = neo4j.GraphDatabase.driver(link, auth=("neo4j", "my_pswd")) print(x.verify_connectivity()) except Exception as e: print(e)
-
answered 2022-03-23 11:47
Thennan
Try
link = "bolt+ssc://" + sys.argv[1]
or
link = "neo4j+ssc://" + sys.argv[1]
instead of
link = "bolt://" + sys.argv[1]
The '+ssc' variants are URI schemes for encrypted sessions that do not check certificates. Refer to the Neo4j Driver manual for more details on the connection URI.
Notes from the Neo4j migration guide
do you know?
how many words do you know
See also questions close to this topic
-
Python File Tagging System does not retrieve nested dictionaries in dictionary
I am building a file tagging system using Python. The idea is simple. Given a directory of files (and files within subdirectories), I want to filter them out using a filter input and tag those files with a word or a phrase.
If I got the following contents in my current directory:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
and I execute the following command in the shell:
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
My output will be:
These files were tagged with "World-Building Tool": data/ world_building_budget.txt hello_world.dat world_builder.spec
My current output isn't exactly like this but basically, I am converting all files and files within subdirectories into a single dictionary like this:
def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree
Right now, my dictionary looks like this:
key:''
.In the following function, I am turning the empty values
''
into empty lists (to hold my tags):def empty_str_to_list(d): for k,v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v)
When I run my entire code, this is my output:
hello_world.dat ['World-Building Tool'] world_builder.spec ['World-Building Tool']
But it does not see
data/world_building_budget.txt
. This is the full dictionary:{'data': {'world_building_budget.txt': []}, 'a.txt': [], 'hello_world.dat': [], 'b.exe': [], 'world_builder.spec': []}
This is my full code:
import os, argparse def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree def empty_str_to_list(d): for k, v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v) parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--filter", action="store", help="keyword to filter files") parser.add_argument("--tag", action="store", help="a tag phrase to attach to a file") parser.add_argument("--get_tagged", action="store", help="retrieve files matching an existing tag") args = parser.parse_args() filter = args.filter tag = args.tag get_tagged = args.get_tagged current_dir = os.getcwd() files_dict = fs_tree_to_dict(current_dir) empty_str_to_list(files_dict) for k, v in files_dict.items(): if filter in k: if v == []: v.append(tag) print(k, v) elif isinstance(v, dict): empty_str_to_list(v) if get_tagged in v: print(k, v)
-
Actaully i am working on a project and in it, it is showing no module name pip_internal plz help me for the same. I am using pycharm(conda interpreter
File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module> File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\__init__.py", line 4, in <module> from pip_internal.utils import _log
I am using pycharm with conda interpreter.
-
Looping the function if the input is not string
I'm new to python (first of all) I have a homework to do a function about checking if an item exists in a dictionary or not.
inventory = {"apple" : 50, "orange" : 50, "pineapple" : 70, "strawberry" : 30} def check_item(): x = input("Enter the fruit's name: ") if not x.isalpha(): print("Error! You need to type the name of the fruit") elif x in inventory: print("Fruit found:", x) print("Inventory available:", inventory[x],"KG") else: print("Fruit not found") check_item()
I want the function to loop again only if the input written is not string. I've tried to type return Under print("Error! You need to type the name of the fruit") but didn't work. Help
-
delete a table form a database using laravel command
i need to delete a database table using laravel artisan command . not like this command php artisan migrate:rollback --step=5
i need to create like this route or controller code .
Route::get('/clear/database', function () {
Artisan::call('cache:clear'); return redirect('/');
});
. i also try public function dd()
{ Schema::drop('table_name'); }
but it not working . gives me error like this SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table
table_name
)no foreign key for the table . what should i do ?
thanks in advance!
-
How to bring data frame into single column from multiple columns in python
I have data format in these multiple columns. So I want to bring all 4 columns of data into a single column.
YEAR Month pcp1 pcp2 pcp3 pcp4 1984 1 0 0 0 0 1984 2 1.2 0 0 0 1984 3 0 0 0 0 1984 4 0 0 0 0 1984 5 0 0 0 0 1984 6 0 0 0 1.6 1984 7 3 3 9.2 3.2 1984 8 6.2 27.1 5.4 0 1984 9 0 0 0 0 1984 10 0 0 0 0 1984 11 0 0 0 0 1984 12 0 0 0 0
-
On the time function of database
When I use Kingbase database in Windows environment, I find that the time function returns the same value in the same transaction. How do I deal with it
-
Deploy VueJS + API app to Azure Static Web App with Gitlab doesn't create functions
I've started creating a small application that will use VueJS as a frontend with Azure Functions as the backend. I was looking at using Azure Static Web Apps to host both components for the application and Gitlab to store / deploy the app.
Everything but the creation of the Azure functions works. Following https://docs.microsoft.com/en-us/azure/static-web-apps/gitlab?tabs=vue
The output from the deploy step, listed below is:
App Directory Location: '/builds/*/valhalla/valhalla-client/dist/spa' was found. Api Directory Location: '/builds/*/valhalla/valhalla-api/dist' was found. Looking for event info Could not get event info. Proceeding Starting to build app with Oryx Azure Static Web Apps utilizes Oryx to build both static applications and Azure Functions. You can find more details on Oryx here: https://github.com/microsoft/Oryx ---Oryx build logs--- Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx You can report issues at https://github.com/Microsoft/Oryx/issues Oryx Version: 0.2.20220131.3, Commit: ec344c058843461525ff03b46031553b6e15a47a, ReleaseTagName: 20220131.3 Build Operation ID: |qAffRWArEg8=.deee9498_ Repository Commit : 7cdd5b61f956e6cb8459b13a42af363c4440a97b Detecting platforms... Could not detect any platform in the source directory. Error: Could not detect the language from repo. ---End of Oryx build logs--- Oryx was unable to determine the build steps. Continuing assuming the assets in this folder are already built. If this is an unexpected behavior please contact support. Finished building app with Oryx Starting to build function app with Oryx ---Oryx build logs--- Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx You can report issues at https://github.com/Microsoft/Oryx/issues Oryx Version: 0.2.20220131.3, Commit: ec344c058843461525ff03b46031553b6e15a47a, ReleaseTagName: 20220131.3 Build Operation ID: |NGXLP5bVBRk=.705477f6_ Repository Commit : 7cdd5b61f956e6cb8459b13a42af363c4440a97b Detecting platforms... Could not detect any platform in the source directory. Error: Could not detect the language from repo. ---End of Oryx build logs--- Oryx was unable to determine the build steps. Continuing assuming the assets in this folder are already built. If this is an unexpected behavior please contact support. [WARNING] The function language could not be detected. The language will be defaulted to node. Function Runtime Information. OS: linux, Functions Runtime: ~3, node version: 12 Finished building function app with Oryx Zipping Api Artifacts Done Zipping Api Artifacts Zipping App Artifacts Done Zipping App Artifacts Uploading build artifacts. Finished Upload. Polling on deployment. Status: InProgress. Time: 0.1762737(s) Status: InProgress. Time: 15.3950401(s) Status: Succeeded. Time: 30.5043965(s) Deployment Complete :) Visit your site at: https://polite-pebble-0dc00000f.1.azurestaticapps.net Thanks for using Azure Static Web Apps! Exiting Cleaning up project directory and file based variables 00:00 Job succeeded
The deploy step appears to have succeeded, and the frontend is deployed, but there are no Azure Functions showing up in this Static Web App. Is something missed here? So far, the Azure Functions I have are the boiler-plate from instantiating a new Azure Function folder.
image: node:latest variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR/valhalla-client/dist/spa' API_PATH: '$CI_PROJECT_DIR/valhalla-api/dist' stages: - install_api - build_api - install_client - build_client - deploy install_api: stage: install_api script: - cd valhalla-api - npm ci artifacts: paths: - valhalla-api/node_modules/ cache: key: node paths: - valhalla-api/node_modules/ only: - master install_client: stage: install_client script: - cd valhalla-client - npm ci artifacts: paths: - valhalla-client/node_modules/ cache: key: node paths: - valhalla-client/node_modules/ only: - master build_api: stage: build_api dependencies: - install_api script: - cd valhalla-api - npm install -g azure-functions-core-tools@3 --unsafe-perm true - npm run build artifacts: paths: - valhalla-api/dist cache: key: build_api paths: - valhalla-api/dist only: - master needs: - job: install_api artifacts: true optional: true build_client: stage: build_client dependencies: - install_client script: - cd valhalla-client - npm i -g @quasar/cli - quasar build artifacts: paths: - valhalla-client/dist/spa cache: key: build_client paths: - valhalla-client/dist/spa only: - master needs: - job: install_client artifacts: true optional: true deploy: stage: deploy dependencies: - build_api - build_client image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully." only: - master
-
Azure Synapse Notebooks Vs Azure Databricks notebooks
I was going through the features of Azure Synapse Notebooks Vs Azure Databricks notebooks.
- Are there any major differences between these apart from the component they belong to ?
- Are there any scenarios where one is more appropriate over other?
-
How to authorize azure container registry requests from .NET CORE C#
I have a web application which creates ContainerInstances, I have specific container registry images I want to use. As a result, I use this code to get my azure container registry
IAzure azure = Azure.Authenticate($"{applicationDirectory}/Resources/my.azureauth").WithDefaultSubscription(); IRegistry azureRegistry = azure.ContainerRegistries.GetByResourceGroup("testResourceGroup", "testContainerRegistryName");
I get this error when the second line of code is hit
The client 'bc8fd78c-2b1b-4596-827e-6a3c918b7c17' with object id 'bc8fd78c-2b1b-4596-827e-6a3c918b7c17' does not have authorization to perform action 'Microsoft.ContainerRegistry/registries/read' over scope '/subscriptions/506b787d-83ef-426a-b7b8-7bfcdd475855/resourceGroups/testapp-live/providers/Microsoft.ContainerRegistry/registries/testapp' or the scope is invalid. If access was recently granted, please refresh your credentials.
I literally have no idea what to do about this. I have seen so many articles talking about Azure AD and giving user roles and stuff. Can someone please walk me step by step how to fix this? I REALLY appreciate the help. Thanks.
I cannot find any client under that object ID so perfectly fine starting from scratch again with a better understanding of what I am doing.
-
Connection failure when using airflow to run python script connecting to neo4j database
I'm trying to use airflow to orchestrate a workflow where a neo4j docker is run and then a python script to query data from the neo4j database (the code runs on AWS EC2 instance). I am able to run the neo4j docker successfully. But when I ran the task of querying the database, I got connection error as:
neo4j.exceptions.ServiceUnavailable: Connection to 127.0.0.1:7687 closed without handshake response
If I manually ran the python script on EC2, it can connect to the neo4j database without any issue. The code I am using is as below:
class Neo4jConnection: def __init__(self, uri, user, pwd): self.__uri = uri self.__user = user self.__pwd = pwd self.__driver = None try: self.__driver = GraphDatabase.driver(self.__uri, auth=(self.__user, self.__pwd)) logger.info('SUCCESS: Connected to the Neo4j Database.') except Exception as e: logger.info('ERROR: Could not connect to the Neo4j Database. See console for details.') raise SystemExit(e) def close(self): if self.__driver is not None: self.__driver.close() def query(self, query, parameters=None, db=None): assert self.__driver is not None, "Driver not initialized!" session = None response = None try: session = self.__driver.session(database=db) if db is not None else self.__driver.session() response = list(session.run(query, parameters)) except Exception as e: logger.info("Query failed:", e) finally: if session is not None: session.close() return response class LoadWikiPathway2Neo4j: def __init__(self): # replace localhost with 127.0.0.1 self.connection = Neo4jConnection(uri="bolt://localhost:7687", user="neo4j", pwd="test") def loadData(self): WIKIPATHWAY_MOUNTED_DATA_VOLUME = "/home/ec2-user/wikipathway_neo4j/data/Human/" # the volume is mounted to neo4j docker WIKIPATHWAY_DATA_DOCKER_VOLUME = "file:///var/lib/neo4j/data/Human" # file path in neo4j docker # connect db graph = self.connection # only run once graph.query('''MATCH (n) DETACH DELETE n''') graph.query('''CALL n10s.graphconfig.init()''') graph.query('''CREATE CONSTRAINT n10s_unique_uri IF NOT EXISTS ON (r:Resource) ASSERT r.uri IS UNIQUE''') graph.query('''call n10s.nsprefixes.removeAll()''') cypher = '''WITH '@prefix biopax: <http://www.biopax.org/release/biopax-level3.owl#> . \ @prefix cito: <http://purl.org/spar/cito/> . \ @prefix dc: <http://purl.org/dc/elements/1.1/> . \ @prefix dcat: <http://www.w3.org/ns/dcat#> . \ @prefix dcterms: <http://purl.org/dc/terms/> . \ @prefix foaf: <http://xmlns.com/foaf/0.1/> . \ @prefix freq: <http://purl.org/cld/freq/> . \ @prefix gpml: <http://vocabularies.wikipathways.org/gpml#> . \ @prefix hmdb: <https://identifiers.org/hmdb/> . \ @prefix ncbigene: <https://identifiers.org/ncbigene/> .\ @prefix owl: <http://www.w3.org/2002/07/owl#> . \ @prefix pav: <http://purl.org/pav/> . \ @prefix prov: <http://www.w3.org/ns/prov#> . \ @prefix pubmed: <http://www.ncbi.nlm.nih.gov/pubmed/> .\ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \ @prefix skos: <http://www.w3.org/2004/02/skos/core#> . \ @prefix void: <http://rdfs.org/ns/void#> . \ @prefix wp: <http://vocabularies.wikipathways.org/wp#> . \ @prefix wprdf: <http://rdf.wikipathways.org/> . \ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . ' as txt \ CALL n10s.nsprefixes.addFromText(txt) yield prefix, namespace RETURN prefix, namespace''' graph.query(cypher) fileLst = os.listdir(WIKIPATHWAY_MOUNTED_DATA_VOLUME) # load data for filename in fileLst: filePath = f'{WIKIPATHWAY_DATA_DOCKER_VOLUME}/{filename}' print(filePath) cypher = f'''CALL n10s.rdf.import.fetch("{filePath}","Turtle")''' logger.info(cypher) graph.query(cypher) logger.info(f"{filename} is loaded") graph.close() def load_wikipathway_files(): data = LoadWikiPathway2Neo4j() data.loadData() with DAG( default_args=default, dag_id=os.path.basename(__file__).replace(".py", ""), schedule_interval=None, catchup=False, start_date=days_ago(1), tags=['s3', 'download_wikipathway'], ) as dag: loadWikipathwayFile = PythonOperator( task_id="load_wikipathway", python_callable=load_wikipathway_files )
-
Return count of relationships instead of all
I wonder if anyone can advise how to adjust the following query so that it returns one relationship with a count of the number of actual relationships rather than every relationship? I have some nodes with many relationships and it's killing the graph's performance.
MATCH (p:Provider{countorig: "XXXX"})-[r:supplied]-(i:Importer) RETURN p, i limit 100
Many thanks
-
How to extract dynamic property names from a json file in Neo4J using Cypher Query
The tags property names are dynamic. e.g. linux and cypher are dynamic in the json. I am trying to extract the dynamic tags and their values and associate them as properties to the Person node. Here is what I have so far:
CALL apoc.load.json("file:///example.json") YIELD value MERGE (p:Person {name: value.name}) ON CREATE SET p.job = value.job, p.department = value.department RETURN p as Person;
example.json:
{ "name": "Harry", "job": "Developer", "tags": { "linux": "awesome", "cypher": "Working on it" }, "department": "IT" }
-
neo4j query to get a specific formated response
I am having a node network in the neo4j database which includes multilevel nodes something like,
parent -> child -> sub child -> ...and so on
Now what I need is I need to write a query that will give me the response in the below format.
nodes = [ { id: parent1, children : [{ id: child1, children: [ { id: sub child1, children: [... So on] }, { id: sub child2, children: [... So on] } ] }] }, { id = parent2, children : [...so on] } ]
-
How to query to get n level depth nodes in neo4j
I want to write a query that will fetch the ciphers(nodes) along with its child nodes to the n-level.
e.g. if any child is having 1 child node and that child node is also having a sub child and that sub child node is also having a sub child node and it continues to the n times. then I want to fetch a result like
{ P: { // parent node info, child: [ // data { a1: { // data child: [ { a2: { // data // And so on... } } ] } }, { b1: { // data child: [ { b2: { // data // And so on... } } ] } } ] }