连接到heroku上托管的Graphenedb时出错
您好,我无法连接到端口7687上的本地主机-服务器正在运行吗?每当python代码执行时出错连接到heroku上托管的Graphenedb时出错,heroku,neo4j,py2neo,graphenedb,Heroku,Neo4j,Py2neo,Graphenedb,您好,我无法连接到端口7687上的本地主机-服务器正在运行吗?每当python代码执行时出错 import os import json from urllib.parse import urlparse, urlunparse from django.shortcuts import render # Create your views here. from py2neo import Graph, authenticate from bottle import get,run,reque
import os
import json
from urllib.parse import urlparse, urlunparse
from django.shortcuts import render
# Create your views here.
from py2neo import Graph, authenticate
from bottle import get,run,request,response,static_file
from py2neo.packages import neo4j
url = urlparse(os.environ.get("GRAPHENEDB_GOLD_URL"))
url_without_auth = urlunparse((url.scheme, ("{0}:{1}").format(url.hostname, url.port), '', None, None, None))
user = url.username
password = url.password
authenticate(url_without_auth,user, password)
graph = Graph(url_without_auth, bolt = False)
#graph = Graph(password='vjsj56@vb')
@get("/")
def get_index():
return static_file("index.html", root="static")
@get("/graph")
def get_graph(self):
print("i was here" )
print("graph start")
results = graph.run(
"MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) "
"RETURN m.title as movie, collect(a.name) as cast "
"LIMIT {limit}", {"limit": 10})
print("graph run the run")
nodes = []
rels = []
i = 0
for movie, cast in results:
#print("i am here")
nodes.append({"title": movie, "label": "movie"})
target = i
i += 1
for name in cast:
print(name)
actor = {"title": name, "label": "actor"}
try:
source = nodes.index(actor)
except ValueError:
nodes.append(actor)
source = i
i += 1
rels.append({"source": source, "target": target})
return {"nodes": nodes, "links": rels}
@get("/search")
def get_search():
try:
q = request.query["q"]
except KeyError:
return []
else:
results = graph.run(
"MATCH (movie:Movie) "
"WHERE movie.title =~ {title} "
"RETURN movie", {"title": "(?i).*" + q + ".*"})
response.content_type = "application/json"
return json.dumps([{"movie": dict(row["movie"])} for row in results])
@get("/movie/<title>")
def get_movie(title):
results = graph.run(
"MATCH (movie:Movie {title:{title}}) "
"OPTIONAL MATCH (movie)<-[r]-(person:Person) "
"RETURN movie.title as title,"
"collect([person.name, head(split(lower(type(r)),'_')), r.roles]) as cast "
"LIMIT 1", {"title": title})
row = results.next()
return {"title": row["title"],
"cast": [dict(zip(("name", "job", "role"), member)) for member in row["cast"]]}
导入操作系统
导入json
从urllib.parse导入urlparse,urlunprase
从django.shortcuts导入渲染
#在这里创建您的视图。
从py2neo导入图中,验证
从瓶子导入获取、运行、请求、响应、静态文件
从py2neo.packages导入neo4j
url=urlparse(os.environ.get(“GRAPHENEDB\u GOLD\u url”))
url_不带_auth=urlunparse((url.scheme,(“{0}:{1}”).format(url.hostname,url.port),“”,无,无,无))
user=url.username
password=url.password
身份验证(不带身份验证、用户、密码的url)
graph=graph(不带认证的url,bolt=False)
#图形=图形(密码=)vjsj56@vb')
@获取(“/”)
def get_index():
返回静态文件(“index.html”,root=“static”)
@获取(“/graph”)
def get_图(自):
打印(“我在这里”)
打印(“图形开始”)
结果=graph.run(
“MATCH(m:Movie)我是Juanjo,来自GrapheneDB
乍一看,代码看起来不错,错误代码指向错误的URL。这可能是环境变量的问题。请检查GRAPHENEDB\u GOLD\u URL变量,好吗
您可以这样做:
$ heroku config:get GRAPHENEDB_GOLD_URL
应该是这样的:
http://<user>:<pass>@XXX.graphenedb.com:24789/db/data
http://:@XXX.graphenedb.com:24789/db/data
(请不要在此处共享您的URL)
如果变量为空,请阅读有关检索GrapheneDB环境变量的更多信息
如果这不是您的问题,或者问题仍然存在,您可以通过我们管理面板上的支持链接与我们联系吗?Heroku团队会将支持票证转发给我们,我们会将与您的数据库相关的所有信息注入票证中
谢谢
胡安霍