简体   繁体   English

与Heroku上托管的Graphenedb的连接错误

[英]Connection error to Graphenedb hosted on heroku

Hi I am getting Unable to connect to localhost on port 7687 - is the server running? 嗨,我越来越无法连接到端口7687上的本地主机-服务器正在运行吗? error whenever my python code executing 每当我的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,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"]]}

this code is running fine on my local syatem but giving connection error when deployed on heroku and graphenedb 此代码在我的本地系统上运行良好,但在heroku和graphenedb上部署时却给出连接错误

exception location: /app/.heroku/python/lib/python3.6/site-packages/py2neo/packages/neo4j/v1/connection.py in connect, line 387 例外位置:/app/.heroku/python/lib/python3.6/site-packages/py2neo/packages/neo4j/v1/connection.py在连接中,第387行

I'm Juanjo, from GrapheneDB. 我是GrapheneDB的Juanjo。

At first glance the code looks fine and the error code points to a wrong URL. 乍看起来,代码看起来不错,并且错误代码指向错误的URL。 It might be a problem with the environment variable. 环境变量可能有问题。 Can you please check your GRAPHENEDB_GOLD_URL variable? 您能否检查您的GRAPHENEDB_GOLD_URL变量?

You can do it like this: 您可以这样做:

$ heroku config:get GRAPHENEDB_GOLD_URL

It should be something like: 应该是这样的:

http://<user>:<pass>@XXX.graphenedb.com:24789/db/data

(please don't share your URL here) (请不要在此处分享您的URL)

If your variable is empty, please read more here on retrieving GrapheneDB environment variables. 如果您的变量为空,请在此处阅读有关获取GrapheneDB环境变量的更多信息。

If that's not your issue, or the problem persists, could you please contact us via the support link on our admin panel? 如果不是您的问题,或者问题仍然存在,请通过管理面板上的支持链接与我们联系吗? Heroku team will forward the support ticket to us and we'll have all the information related to your database injected into the ticket. Heroku团队会将支持票转发给我们,我们会将与您的数据库相关的所有信息注入票中。

Thanks, 谢谢,

Juanjo 胡安乔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM