py2neo.database.status.Unauthorized in Neo4j 3.0.3 - python

I've tried to access from a python program to the Neo4j 3.0 database but the following error is shown:
File "C:\Python27\lib\py2neo\database\http.py", line 157, in get raise Unauthorized(self.uri.string)
py2neo.database.status.Unauthorized: http://localhost:7474/db/data/
There is already a post of the same topic opened, but it's in version 2.2.
My code is:
authenticate("localhost:7474", "neo4j", "neo4j")
graph_db = Graph("http://localhost:7474/db/data/")
Which is exactly the same as in version 2.2, as it is specified in http://py2neo.org/v3/database.html.
I've also tried to do it like this:
graph_db = Graph("http://localhost:7474/db/data/", user="neo4j", password="neo4j")
But I get the same result.
Does anyone know where is the problem?
Thanks in advance.

Access the database through the web interface (http://localhost:7474/browser/), you have to set a new password at the first log in.
Then, this should work:
from py2neo
g = Graph('http://localhost:7474/db/data', user='neo4j', password='new_password')

Related

Tapo plug using python with PyP100 library login error

I am using the basic script from the repository to try and connect to a Tapo P110 plug. Clearly I am using my ip/email/pword.
from PyP100 import PyP110
p110 = PyP110.P110("192.168.X.X", "email#gmail.com", "Password123") #Creating a P110 plug object
p110.handshake() #Creates the cookies required for further methods
p110.login() #Sends credentials to the plug and creates AES Key and IV for further methods
#PyP110 has all PyP100 functions and additionally allows to query energy usage infos
p110.getEnergyUsage() #Returns dict with all the energy usage
But I am getting this error.
Traceback (most recent call last):
File "c:\Users\xxxx\xxxx\Add-hoc analysis projects\tapo_plug_energy_monitor\Python\Basic_Tapo_script.py", line 9, in <module>
p110.getDeviceInfo()
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\PyP100\PyP100.py", line 236, in getDeviceInfo
URL = f"http://{self.ipAddress}/app?token={self.token}"
AttributeError: 'P110' object has no attribute 'token'
I should note I tried to ping the ip and all packets transmitted and received correctly. It is login() that causes the error but I have checked login details and they seem to be correct. Any help appreciated.
So the problem was because of an update to the Tapo P110 firmware version 1.0.16
The current solution is to make a small change to PyP100.py see below link.
https://github.com/fishbigger/TapoP100/issues/76

Can't connect to Neo4j Aura with Neomodel

I'm trying to start a project using Neo4j Aura and neomodel. I've found this post and set up my connection as suggested, however when I try to run my project I get the following error:
ValueError: Expecting url format: bolt://user:password#localhost:7687 got neo4j+s://myuser:mypass#mydb.databases.neo4j.io
I've checked the neomodel code and it specifically checks for the bolt protocol and won't continue with the neo4j+s protocol. This differs from what is suggested in the post I linked - am I missing something? I would greatly appreciate a hint in the right direction.
Here is the example code I'm trying to run:
import os
from neomodel import (config, StructuredNode, StringProperty, IntegerProperty,
UniqueIdProperty, RelationshipTo)
from dotenv import load_dotenv
if __name__ == '__main__':
load_dotenv()
user = os.environ['NEO4J_USERNAME']
psw = os.environ['NEO4J_PASSWORD']
uri = os.environ['NEO4J_URI']
config.DATABASE_URL = 'neo4j+s://{}:{}#{}'.format(user, psw, uri)
class Country(StructuredNode):
code = StringProperty(unique_index=True, required=True)
class Person(StructuredNode):
uid = UniqueIdProperty()
name = StringProperty(unique_index=True)
age = IntegerProperty(index=True, default=0)
# traverse outgoing IS_FROM relations, inflate to Country objects
country = RelationshipTo(Country, 'IS_FROM')
jim = Person(name='Jim', age=3).save() # Create
jim.age = 4
jim.save() # Update, (with validation)
Please advise your neo4j version and neo4j driver version. Bolt protocol is previously used in neo4j drivers 1.7 while neo4j protocol is for neo4j version 4.x. This protocol neo4j+s is equivalent to bolt+routing in older version. Then, I tried your code and it is working well. Notice the db aura uri at the bottom of the image.
To check your neo4j versions, open a terminal and type "pip freeze | grep neo4j".
This is my driver version:
neo4j==4.4.5
neo4j-driver==4.3.6
neomodel==4.0.8
Result:

running a simple pdblp code to extract BBG data

I am currently logged on to my BBG anywhere (web login) on my Mac. So first question is would I still be able to extract data using tia (as I am not actually on my terminal)
import pdblp
con = pdblp.BCon(debug=True, port=8194, timeout=5000)
con.start()
I got this error
pdblp.pdblp:WARNING:Message Received:
SessionStartupFailure = {
reason = {
source = "Session"
category = "IO_ERROR"
errorCode = 9
description = "Connection failed"
}
}
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/prasadkamath/anaconda2/envs/Pk36/lib/python3.6/site-packages/pdblp/pdblp.py", line 147, in start
raise ConnectionError('Could not start blpapi.Session')
ConnectionError: Could not start blpapi.Session
I am assuming that I need to be on the terminal to be able to extract data, but wanted to confirm that.
This is a duplicate of this issue here on SO. It is not an issue with pdblp per se, but with blpapi not finding a connection. You mention that you are logged in via the web, which only allows you to use the terminal (or Excel add-in) within the browser, but not outside of it, since this way of accessing Bloomberg lacks a data feed and an API. More details and alternatives can be found here.

Using the recommended python parse.com library to wrap their REST api, why does the following occur

Code:
for k in dir(parse_rest.User):
print parse_rest.User[k]
Error:
Traceback (most recent call last):
File "/home/ntresch/Development/webapp/appcode.py", line 53, in <module>
for k in dir(parse_rest.User):
AttributeError: 'module' object has no attribute 'User'
The docs show the following:
#Users
#You can sign up, log in, modify or delete users as well, using the User object. You sign a user up as follows:
u = parse_rest.User.signup("dhelmet", "12345", phone="555-555-5555")
#or log in an existing user with
u = parse_rest.User.login("dhelmet", "12345")
# Once a User has been logged in, it saves its session so that it can be edited or deleted:
u.highscore = 300
u.save()
u.delete()
I really want to know what all I can do with the user object. This behavior seems wonky.
This was a case of (at the time) out-of-date documentation, fixed as of 3/11/2013. The way to access the User class is not parse_rest.User but:
from parse_rest.user import User
The answer is don't use that library. My colleague has one we home rolled checked into our source tree and we're planning on releasing one. When we do I will post a link here for completeness. :)

Python Mechanize + GAEpython code

I am aware of previous questions regarding mechanize + Google App Engine,
What pure Python library should I use to scrape a website?
and Mechanize and Google App Engine.
Also there is some code here, which I cannot get to work on app engine, throwing
File “D:\data\eclipse-php\testpy4\src\mechanize\_http.py”, line 43, in socket._fileobject(”fake socket”, close=True)
File “C:\Program Files (x86)\Google\google_appengine\google\appengine\dist\socket.py”, line 42, in _fileobject
fp.fileno = lambda: None
AttributeError: ’str’ object has no attribute ‘fileno’
INFO 2009-12-14 09:37:50,405 dev_appserver.py:3178] “GET / HTTP/1.1″ 500 -
Is anybody willing to share their working mechanize + appengine code?
I have solved this problem, just change the code of mechanize._http.py, about line 43,
from:
try:
socket._fileobject("fake socket", close=True)
except TypeError:
# python <= 2.4
create_readline_wrapper = socket._fileobject
else:
def create_readline_wrapper(fh):
return socket._fileobject(fh, close=True)
to:
try:
# fixed start -- fixed for gae
class x:
pass
# the x should be an object, not a string,
# This is the key
socket._fileobject(x, close=True)
# fixed ended
except TypeError:
# python <= 2.4
create_readline_wrapper = socket._fileobject
else:
def create_readline_wrapper(fh):
return socket._fileobject(fh, close=True)
I managed to get mechanize code that runs on GAE, many thanks to
MStodd,
from GAEMechanize project http://code.google.com/p/gaemechanize/ and
If anybody needs the code, you can contact MStodd !
ps: the code is not on google code, so you have to contact the owner..
Cheers
don
I've uploaded the source of the gaemechanize project to a new project: http://code.google.com/p/gaemechanize2/
Insert usual caveats.

Categories

Resources