2017-04-25 76 views
0

嗨我無法連接到端口7687上的本地主機 - 服務器運行嗎?錯誤,每當我執行連接Heroku上託管的Graphenedb錯誤

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='[email protected]') 


@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"]]} 

這段代碼Python代碼運行良好對我的本地系統的研究與開發,但部署在Heroku上時和graphenedb

異常的位置讓連接錯誤:/app/.heroku/python/lib/python3 .6/site-packages/py2neo/packages/neo4j/v1/connection.py in connect,line 387

回答

1

我是來自GrapheneDB的Juanjo。

乍一看,代碼看起來很好,錯誤代碼指向了錯誤的URL。這可能是環境變量的問題。你能檢查你的GRAPHENEDB_GOLD_URL變量嗎?

你可以這樣說:

$ heroku config:get GRAPHENEDB_GOLD_URL 

它應該是這樣的:

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

如果變量是空的(請不要在這裏分享你的URL)

,關於檢索GrapheneDB環境變量,請閱讀here

如果這不是您的問題,或者問題仍然存在,您可以通過我們的管理面板上的支持鏈接與我們聯繫嗎? Heroku團隊會將支持憑單轉發給我們,我們將把所有與您的數據庫相關的信息注入票證。

感謝,

Juanjo