当前位置: 首页>>代码示例>>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;未经允许,请勿转载。