當前位置: 首頁>>代碼示例>>Python>>正文


Python v1.basic_auth方法代碼示例

本文整理匯總了Python中neo4j.v1.basic_auth方法的典型用法代碼示例。如果您正苦於以下問題:Python v1.basic_auth方法的具體用法?Python v1.basic_auth怎麽用?Python v1.basic_auth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在neo4j.v1的用法示例。


在下文中一共展示了v1.basic_auth方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_db_client

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def get_db_client(dbhost, dbuser, dbpass, bolt=False):
    """Return a Neo4j DB session. bolt=True uses bolt driver"""    

    if verbose > 4:
        print("DB Creds", dbhost, dbuser, dbpass)

    if bolt:
        bolt_url = "bolt://" + dbhost
        auth_token = basic_auth(dbuser, dbpass)
        try:
            driver = GraphDatabase.driver(bolt_url, auth=auth_token, max_pool_size=5)
            bolt_session = driver.session()
            return bolt_session
        except Exception as e:
            print("Database connection/authentication error:", e)
            sys.exit(1)
    else:
        login = "http://{0}:{1}@{2}:7474/db/data/".format(dbuser, dbpass, dbhost)
        py2neo_session = Graph(login)
        return py2neo_session 
開發者ID:yantisj,項目名稱:netgrph,代碼行數:22,代碼來源:__init__.py

示例2: connect

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def connect(self):
        self.neo4j_driver = GraphDatabase.driver(
            self.neo4j_url,
            auth=basic_auth(self.neo4j_user, self.neo4j_password))
        return self.neo4j_driver 
開發者ID:ashapochka,項目名稱:saapy,代碼行數:7,代碼來源:neo4j_client.py

示例3: __new__

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def __new__(cls, *args, **kwargs):
		"""
		Return neo4j-driver ou neo4jrestclient object
		"""
		_auth = None
		if kwargs and ('user' or 'password') in list(kwargs.keys()):
			user = kwargs['user']
			password = kwargs['password']
			if 'bolt://' in cls._default_host:
				_auth = basic_auth(user, password)
			else:
				_url = 'http://{0}:{1}@localhost:7474'.format(user, password)
				cls.host = _url

		if 'bolt://' in cls._default_host:
			driver = Neo4j3.driver(cls._default_host)
			if _auth:
				driver.auth = _auth

			cls._graph = Cypher(driver)
			return cls._graph

		elif cls.host is not None and type(cls.host) is str:
			cls._graph = Neo4j2(cls.host)
			return cls._graph

		else:
			cls._graph = Neo4j2(cls._default_host)
			return cls._graph 
開發者ID:RenanPalmeira,項目名稱:pyneo4j,代碼行數:31,代碼來源:graph.py

示例4: __init__

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def __init__(self, **kwargs):
        #super(Neo4JConn, self).__init__()
        config = {
            'host': kwargs['db_addr'],
            'port': kwargs['db_port'],
            'user': kwargs['username'],
            'password': kwargs['password']
        }
        driver = GraphDatabase.driver(
                "bolt://%s:%d" % (config['host'], config['port']),
                auth=basic_auth(config['user'], config['password']))
        self.__session = driver.session() 
開發者ID:popart,項目名稱:wikipath,代碼行數:14,代碼來源:neo4jconn.py

示例5: get_facebook_event

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def get_facebook_event(fb_event_id, fb_token):
    # get the event from facebook and put into neo4j
    session = GraphDatabase.driver("bolt://{}:7687".format(neo4j_dbip),
                                   auth=basic_auth("neo4j", "{}".format(neo4j_password))).session()
    url = 'https://graph.facebook.com/v2.10/{}'.format(fb_event_id)
    parameters = {'access_token': fb_token}
    r = requests.get(url, params=parameters)
    result = json.loads(r.text)
    print(result)
    fb_event_name = result['name']
    fb_event_id = result['id']

    try:
        fb_event_description = result['description']
    except:
        fb_event_description = ''
    fb_event_start_time = result['start_time']

    insert_query = '''
    MERGE (n:fb_event{fb_event_id:{fb_event_id},description:{description},event_name:{event_name},start_time:{start_time}})
    '''
    session.run(insert_query, parameters={"fb_event_id": fb_event_id, "description": fb_event_description,
                                          "event_name": fb_event_name, "start_time": fb_event_start_time
                                          })
    session.close()


# Create host node 
開發者ID:suprfanz,項目名稱:flask-fb-neo4j-d3,代碼行數:30,代碼來源:run_get_facebook_event.py

示例6: get_event_owner

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def get_event_owner(fb_event_id, fb_token):
    # get the host from facebook and put into neo4j
    session = GraphDatabase.driver("bolt://{}:7687".format(neo4j_dbip),
                                   auth=basic_auth("neo4j", "{}".format(neo4j_password))).session()
    url = 'https://graph.facebook.com/v2.7/{}/?fields=owner'.format(fb_event_id)
    parameters = {'access_token': fb_token}
    r = requests.get(url, params=parameters)
    result = json.loads(r.text)
    print(result)
    host_name = result['owner']['name']
    host_id = result['owner']['id']
    insert_query = '''
    MERGE (n:host{host_name:{host_name},host_id:{host_id}})
    '''
    insert_query_rel = '''
    MATCH (n:host),(n1:fb_event)
    WHERE n.host_id = {host_id} AND n1.fb_event_id = {fb_event_id}
    MERGE (n)-[r:HOST]->(n1)
    SET r.source = {host_id}
    SET r.target = {fb_event_id}
    '''
    session.run(insert_query, parameters={"host_name": host_name,
                                          "host_id": host_id
                                          })

    session.run(insert_query_rel, parameters={"host_id": host_id,
                                              "fb_event_id": fb_event_id
                                              })
    session.close() 
開發者ID:suprfanz,項目名稱:flask-fb-neo4j-d3,代碼行數:31,代碼來源:run_get_facebook_event.py

示例7: __init__

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def __init__(self, event, fb_token):
        self.fb_token = fb_token
        self.fb_event_id = event
        self.session = GraphDatabase.driver("bolt://{}:7687".format(neo4j_dbip),
                                            auth=basic_auth("neo4j", "{}".format(neo4j_password))).session()

    # Pull Event from Facebook 
開發者ID:suprfanz,項目名稱:flask-fb-neo4j-d3,代碼行數:9,代碼來源:run_get_facebook_event_class.py

示例8: __init__

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def __init__(self, id, name, profile_url, access_token):
        self.id = id
        self.name = name
        self.profile_url = profile_url
        self.access_token = access_token

        self.session = GraphDatabase.driver("bolt://{}:7687".format(neo4j_dbip),
                                            auth=basic_auth("neo4j", "{}".format(neo4j_password))).session() 
開發者ID:suprfanz,項目名稱:flask-fb-neo4j-d3,代碼行數:10,代碼來源:models.py

示例9: __init__

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def __init__(self,url,cache_data):
		proto = "{}/".format('/'.join(url.split('/')[:2]))
		try:
			userpwd = url.split('/')[2].split('@')[0]
		except:
			userpwd = ":"

		try:
			uri = url.split('@')[1]
		except:
			uri = '/'.join(url.split('/')[2:])

		data = ["{}{}".format(proto,uri),userpwd.split(':')[0], userpwd.split(':')[1]]
		# TODO: Store this relations in a redis-like cache
		self.cache = Cache(cache_data)
		self.cache.create_cache(self.DEST_RELS)
		self.cache.create_cache(self.DOM_RELS)
		self.cache.create_cache(self.SRC_RELS)
		self.cache.create_cache(self.SRCDST_RELS)
		self.cache.create_cache(self.SRCLOGIN_RELS)
		self.cache.create_cache(self.SESSIONS_RELS)
		self.cache.create_cache(self.FROM_SESSIONS)
		self.cache.create_cache(self.USER_LIST)
		self.cache.create_cache(self.DOM_LIST)
		self.cache.create_cache(self.SRV_LIST)
		self.cache.create_cache(self.SRVDOM_RELS)

		# setup neo4j
		self.drv = GraphDatabase.driver(data[0], auth=basic_auth(data[1], data[2]))
		self.neo = self.drv.session()
		self.neo.run("CREATE INDEX ON :User(sid)")
		self.neo.run("CREATE INDEX ON :Computer(name)")
		self.neo.run("CREATE INDEX ON :Domain(name)") 
開發者ID:THIBER-ORG,項目名稱:userline,代碼行數:35,代碼來源:neo4j.py

示例10: connect

# 需要導入模塊: from neo4j import v1 [as 別名]
# 或者: from neo4j.v1 import basic_auth [as 別名]
def connect(self, authentication_options):
        """
        The connect method to create a new instance of the db_driver

        :param authentication_options: Username, password and host
        :return: None
        :rtype: None
        :raises: InvalidOptionsException
        """
        if authentication_options is None:
            raise InvalidOptionsException()

        user_name = authentication_options.get("user_name")
        user_pass = authentication_options.get("user_password")
        host = authentication_options.get("host")

        if user_name is None or user_pass is None or host is None:
            raise InvalidOptionsException()

        try:
            self.driver = GraphDatabase.driver("bolt://{}".format(host), auth=basic_auth(user_name, user_pass))

        except SessionError as e:
            raise InvalidOptionsException(e)

        self._create_session() 
開發者ID:DLR-SC,項目名稱:prov-db-connector,代碼行數:28,代碼來源:neo4jadapter.py


注:本文中的neo4j.v1.basic_auth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。