Neo4jrestclient error Unable to get root - python

Earlier my code was working fine, suddenly while running my Python script:
**from neo4jrestclient.client import GraphDatabase
from bottle import route, run,template,post,request,redirect
gdb = GraphDatabase("http://localhost:7474/db/data/")*
#route('/home')
def open_home():
username=""
parties=[]
return template('home',dict(username=username,parties=parties))
This error shows up:
Traceback (most recent call last): > File "bottle3.py", line 4, in > gdb = > GraphDatabase("localhost:7474/db/data/") File > "/usr/local/lib/python2.7/dist-packages/neo4jrestclient/client.py", > > line 78, in init > raise NotFoundError(response.status_code, "Unable get root") neo4jrestclient.exceptions.NotFoundError: Code > [411]: Length Required. > Client must specify Content-Length.. Unable > get root

Have you removed all nodes in the database?
Have you upgraded to Neo4j >=2.0? With the release of 2.0.0 RC1 the database no longer contains a default node 0 (reference node), previously known as root.
I can recommend neo4jdb-python for an up to date python driver.

Related

Call speedtest.Speedtest() from Python using --secure (to avoid speedtest.ConfigRetrievalError: HTTP Error 403: Forbidden)

I have a small Python3-script like this:
import speedtest
# Speedtest
test = speedtest.Speedtest() # <--- line 4
test.get_servers()
best = test.get_best_server()
print(f"Found: {best['host']} located in {best['country']}")
The first time I run it, it works and everything is fine; it outputs:
Found: speedtest.witcom.cloud:8080 located in Germany
Happy days.
The second time (and subsequel times) that I run the script, I get this error:
Traceback (most recent call last):
File "/Users/zeth/Code/pinger/pinger.py", line 4, in <module>
test = speedtest.Speedtest()
File "/usr/local/lib/python3.9/site-packages/speedtest.py", line 1095, in __init__
self.get_config()
File "/usr/local/lib/python3.9/site-packages/speedtest.py", line 1127, in get_config
raise ConfigRetrievalError(e)
speedtest.ConfigRetrievalError: HTTP Error 403: Forbidden
When Googling around, I saw that I could also call this module straight from the command line, but just running this:
$ speedtest-cli
That gives me the same kind of error:
Retrieving speedtest.net configuration...
Cannot retrieve speedtest configuration
ERROR: HTTP Error 403: Forbidden
But if I run the direct cli-command: speedtest-cli --secure ( docs for the --secure-flag ), then it goes through and outputs this:
Retrieving speedtest.net configuration...
Testing from Deutsche Telekom AG (212.185.228.168)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by hotspot.koeln (Cologne) [3.44 km]: 28.805 ms
Testing download speed................................................................................
Download: 30.01 Mbit/s
Testing upload speed......................................................................................................
Upload: 8.68 Mbit/s
The question
I can't figure out how to change this Python-line: test = speedtest.Speedtest() to use a --secure-flag (nor via HTTPS).
The documentation for speedtest-cli is scarce.
Other attempts
I found this solution here: Python Speedtest facing problems with certification _ssl.c:1056, that suggests manually approving the certificates.
But in this directory: /Volumes/Macintosh HD/Applications/ I don't have anything called Python3.9. I have python3.9 installed via Brew. And I'm on a Mac.
I could do this:
test = speedtest.Speedtest(secure=True)
I looked into the source code myself, in this directory:
vim /usr/local/lib/python3.9/site-packages/speedtest.py
Where I would see the function was defined like this:
class Speedtest(object):
"""Class for performing standard speedtest.net testing operations"""
def __init__(self, config=None, source_address=None, timeout=10,
secure=False, shutdown_event=None):
self.config = {}
self._source_address = source_address
self._timeout = timeout
self._opener = build_opener(source_address, timeout)
self._secure = secure
...
...
...

Pdb error while debugging python app with serverless launched offline

I have problem with debugging my view function with
import pdb; pdb.set_trace()
placed inside it and serverless launched as
> sls offline start
in console.
Namely, making correspondent GET request I receive the following error:
Python: > /.../handler.py(88)get_results()
-> request_params = event.query_params
Python: (Pdb)
Python: 2019-02-20 18:37:43,648 [ERROR] | ...
Traceback (most recent call last):
...
File ".../handler.py", line 88, in get_results
...
File "/usr/lib/python3.6/bdb.py", line 51, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python3.6/bdb.py", line 70, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Google suggests that the problem is in the inability of serverless process to read from stdin, but I don't know how to handle this problem.
Any suggestions?
I found a solution here https://stackoverflow.com/a/26975795/4388451:
create two fifos:
mkfifo fifo_stdin
mkfifo fifo_stdout
in one terminal
In the same terminal open stdout on background, and write to stdin:
cat fifo_stdout & cat > fifo_stdin
In python code create the the pdb object, and use it:
import pdb
mypdb = pdb.Pdb(stdin=open('fifo_stdin', 'r'), stdout=open('fifo_stdout', 'w'))
....
mypdb.set_trace()
Run python code from the folder where fifos were placed (or place fifos in the first step in the folder with python code) in another terminal
Now I am able to use pdb in first console!
PS
It is useful to use --noTimeout option while debugging: sls offline --noTimeout

Python -> AttributeError: 'module' object has no attribute 'main'

I am working on a Raspberry Pi 3 and I am trying to visualize some values of sensors on Munin. I am using Python in order to execute scripts on Munin.
I found a script to test and I am trying to execute it but I got the following error :
Traceback (most recent call last):
File "cpu_field", line 23, in
munin.main()
AttributeError: 'module' object has no attribute
'main'
This is the script : https://github.com/CooledCoffee/python-munin/
Of course, I added at the beginning :
!/usr/bin/env python
But, what I didn't understand is that others scripts are working like this one :
https://gist.github.com/tomoconnor/813813
Would be nice if you could put the code in the question as well.
Anyways. The python-munin you use is entirely different and provides no main() function (as it called in line 23). Names for python modules are not protected and
'munin' is a obvious choice used by more than one developer.
The first script should run with the module you get with
pip install python-munin
The other script uses this python-munin module and you probably get it directly from the git repository. They are not compatible.
So, this is the code I am using :
> #!/usr/bin/env python
>
> import munin
>
> category = 'system' fields = [
> 'load1',
> 'load5',
> 'load15', ] vlabel = 'load'
>
> def values():
> with open('/proc/loadavg') as f:
> data = f.read()
> load1, load5, load15 = [float(s) for s in data.split()[:3]]
> return {
> 'load1': load1,
> 'load5': load5,
> 'load15': load15,
> }
>
> if __name__ == '__main__':
> munin.main()
This is the answer I got with sudo python xxx, I got the same answer with sudo munin-run xxx :
pi#dex:/etc/munin/plugins $ sudo python first
Traceback (most recent call last):
File "first", line 24, in <module>
munin.main()
AttributeError: 'module' object has no attribute 'main'
I thin you are right because when I installed munin with
pip install python-munin
it worked. But, then I installed this python-munin module and it didn't work anymore. I removed the folder python-munin but I still got the same error.
How can I remove properly the previous folder ?

libtorrent-python problems, "no such file or directory" when there clearly is

First of all, here's the code
#!/usr/bin/env python3.4
import libtorrent as lt
import os
fs = lt.file_storage()
lt.add_files(fs, "/var/mirror/packages/") # There are two files in this directory
t = lt.create_torrent(fs, flags = 1&8&16) # 1 = Optimization, 8 = Symbolic links, 16 = calculate file hashes.
t.add_tracker("udp://tracker.[private].com:80")
print(os.path.isdir("/var/mirror/packages/"))
lt.set_piece_hashes(t,"/var/mirror/packages/")
print(t.generate())
And here's what happens when I run it
True
Traceback (most recent call last):
File "./test.py", line 9, in <module>
lt.set_piece_hashes(t,"/var/mirror/packages/")
RuntimeError: No such file or directory
This is the page I got this from
I have browsed around the bindings, but I can't find the set_piece_hashes sources. It returns the same error code when I change the path to "." or "/" (keeping the add_files path the same)
Anyone know what I'm doing wrong? I can't find any sort of documentation other than the site I linked above
Turns out set_piece_hashes wants the parent directory of the directory you created the filestore with. After I fixed that, I now get another error, which is a known bug in libtorrent here

name 'OSPF_Link' is not defined

I have a python script like this:
#!/usr/bin/env python
from scapy.all import *
from ospf import *
def ourSend(packet):
sendp(packet,iface='eth1')
host1='10.0.3.2'
advr_routers='10.0.8.7'
host2='10.0.2.2'
sequence=0x80000918
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
link2host2 = OSPF_Link(id=host2,data='10.0.2.2',type=2,metric=1)
link2victim = OSPF_Link(id="192.168.200.20",data="255.255.255.255",type=3,metric=1)
IPlayer=IP(src='10.0.1.2',dst='224.0.0.5')
OSPFHdr=OSPF_Hdr(src='10.0.6.1')
rogueLsa=Ether()/IPlayer/OSPFHdr/OSPF_LSUpd(lsacount=1,lsalist=[OSPF_Router_LSA(options=0x22,id='10.0.3.1',adrouter=advr_routers,seq=sequence,\
linkcount=3,linklist=[link2victim,link2host1,link2host2])])
ourSend(rogueLsa)
When I run it it has an scapy error.. So I resolved it with git pyrt...
now when I want to run the python script I have other error:
$ python scipt.py
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
File "s.py", line 19, in <module>
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
NameError: name 'OSPF_Link' is not defined
Thank you
I Should separately get ospf.py again and run my script.
This is what I tried and worked...
When you git pyrt The module OSPF_Link can't be added. SO I used the ospf.py again and problem is solved now....

Categories