KeyError: 'ifname' in convert an OpenWRT tar.gz to NetJSON - linux

I was trying to use the netjsonconfig command line utility and tried the
convert an OpenWRT tar.gz to NetJSON and print to standard output (with 4 space indentation) utility
netjsonconfig --native network --backend openwrt --method json -a indent=" "
But following error shows,
ubuntu#ip-172-31-21-48:~/netjsontest$ netjsonconfig --native backup.tar.gz --backend openwrt --method json -a indent=" "
Traceback (most recent call last):
File "/usr/local/bin/netjsonconfig", line 180, in <module>
instance = backend_class(**options)
File "/usr/local/lib/python2.7/dist-packages/netjsonconfig/backends/base/backend.py", line 47, in __init__
self.parse(native)
File "/usr/local/lib/python2.7/dist-packages/netjsonconfig/backends/base/backend.py", line 280, in parse
self.to_netjson()
File "/usr/local/lib/python2.7/dist-packages/netjsonconfig/backends/base/backend.py", line 293, in to_netjson
value = converter.to_netjson()
File "/usr/local/lib/python2.7/dist-packages/netjsonconfig/backends/base/converter.py", line 108, in to_netjson
result = self.to_netjson_loop(block, result, index + 1)
File "/usr/local/lib/python2.7/dist-packages/netjsonconfig/backends/openwrt/converters/wireless.py", line 118, in to_netjson_loop
interface = self.__get_netjson_interface(block)
File "/usr/local/lib/python2.7/dist-packages/netjsonconfig/backends/openwrt/converters/wireless.py", line 246, in __get_netjson_interface
if interface['name'] == wifi['ifname']:
KeyError: 'ifname'
`
Python version: Python 2.7.6
OS: ubuntu: 14.04
Can anyone help me to get this fixed?
Edit :
http://netjsonconfig.openwisp.org/en/stable/general/commandline_utility.html

What does network contain?
The exception you're getting looks like a bug though, you shouldn't get an exception but a failure.
Maybe is better to open an issue in https://github.com/openwisp/netjsonconfig

Related

python module autopep8 problem in Linux terminal

I run ubuntu by wsl 2. I use python 3.10 version. Now when I run autopep8 the problem of your below picture comes. How can it be fixed?
when I type autopep8 --in-place -a filename.py ,this problem appears
Traceback (most recent call last):
File "/home/asib/.local/bin/autopep8", line 8, in <module>
sys.exit(main())
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 4518, in main
results = fix_multiple_files(args.files, args, sys.stdout)
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 4413, in fix_multiple_files
ret = _fix_file((name, options, output))
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 4383, in _fix_file
return fix_file(*parameters)
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 3569, in fix_file
original_source = readlines_from_file(filename)
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 195, in readlines_from_file
with open_with_encoding(filename) as input_file:
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 172, in open_with_encoding
encoding = detect_encoding(filename, limit_byte_check=limit_byte_check)
File "/home/asib/.local/lib/python3.10/site-packages/autopep8.py", line 182, in detect_encoding
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
ModuleNotFoundError: No module named 'lib2to3'
I want when I give autopep8 command, it will work.
For example: autopep8 --in-place -a filename.py

psutil.AccessDenied Error while trying to load StanfordCoreNLP

I'm trying to load the package StanfordCoreNLP to get the correct parsing for the movie reviews presented in their page (https://nlp.stanford.edu/sentiment/treebank.html): (I'm using MAC)
nlp = StanfordCoreNLP("/Users//NLP_models/stanford-corenlp-full-2018-01-31")
But get the error:
Traceback (most recent call last):
File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 295, in wrapper
return fun(self, *args, **kwargs)
File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 480, in connections
rawlist = cext.proc_connections(self.pid, families, types)
PermissionError: [Errno 1] Operation not permitted
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 2411, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1802, in run
launch(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
...
...
...
File "/Users/anaconda3/lib/python3.6/site-packages/stanfordcorenlp/corenlp.py", line 79, in __init__
if port_candidate not in [conn.laddr[1] for conn in psutil.net_connections()]:
File "/Users/anaconda3/lib/python3.6/site-packages/psutil/__init__.py", line 2191, in net_connections
return _psplatform.net_connections(kind)
File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 229, in net_connections
cons = Process(pid).connections(kind)
File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 300, in wrapper
raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=5488)
I tried
conda update conda
conda update anaconda-navigator
conda update navigator-updater
But it didn't help.
Any ideas??
Thanks!!
I have the same problem, and I got it work by running the code using sudo like below:
sudo /Users/edamame/workspace/git/chinese_nlp/venv/bin/python3 chinese_segmenter1.py
Hope this works for you as well.
Same problem here.
A lot of discussion of this points to https://github.com/ContinuumIO/anaconda-issues/issues/1984, which suggests updating to the latest Navigator, and running as root (via sudo).
I've tried both and see no change at all (you may be more fortunate).
https://github.com/Lynten/stanford-corenlp/issues/26 references a tweaked version of corenlp.py that claims to avoid the problem, though I haven't gotten it to work either.
This problem seems to be specific to Mac OS X which would not allow Python to check the current port.
Comment this portion of code of corenlp.py file:
if self.port is None:
for port_candidate in range(9000, 65535):
if port_candidate not in [conn.laddr[1] for conn in psutil.net_connections()]:
self.port = port_candidate
break
if self.port in [conn.laddr[1] for conn in psutil.net_connections()]:
raise IOError('Port ' + str(self.port) + ' is already in use.')
Replace by this line:
self.port = 9999
Source: https://github.com/Lynten/stanford-corenlp/issues/26#issuecomment-445507811
Another solution is to run StanfordCoreNLP with a sudo command line.

cannot parse sentence using stanford parser even i have set environment variables

I am using python 3.5.
I downloaded the Stanford parser and extracted it. I have also set the environment variable properly and it got set properly. But when I ran a sentence and tried to parse I am getting an error.
This is the error:
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
sp.parse("this is a sentence".split())
File "C:\Users\MAHESH\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\parse\api.py", line 45, in parse
return next(self.parse_sents([sent], *args, **kwargs))
File "C:\Users\MAHESH\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\parse\stanford.py", line 120, in parse_sents
cmd, '\n'.join(' '.join(sentence) for sentence in sentences), verbose))
File "C:\Users\MAHESH\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\parse\stanford.py", line 216, in _execute
stdout=PIPE, stderr=PIPE)
File "C:\Users\MAHESH\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\internals.py", line 134, in java
raise OSError('Java command failed : ' + str(cmd))
OSError: Java command failed : ['java.exe', '-mx1000m', '-cp', 'C:/Users/MAHESH/stanfordparser/stanford-parser-full-2015-04-20\\stanford-parser-3.5.2-models.jar;C:/Users/MAHESH/stanfordparser/stanford-parser-full-2015-04-20\\ejml-0.23.jar;C:/Users/MAHESH/stanfordparser/stanford-parser-full-2015-04-20\\stanford-parser-3.5.2-javadoc.jar;C:/Users/MAHESH/stanfordparser/stanford-parser-full-2015-04-20\\stanford-parser-3.5.2-models.jar;C:/Users/MAHESH/stanfordparser/stanford-parser-full-2015-04-20\\stanford-parser-3.5.2-sources.jar;C:/Users/MAHESH/stanfordparser/stanford-parser-full-2015-04-20\\stanford-parser.jar', 'edu.stanford.nlp.parser.lexparser.LexicalizedParser', '-model', 'edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz', '-sentences', 'newline', '-outputFormat', 'penn', '-tokenized', '-escaper', 'edu.stanford.nlp.process.PTBEscapingProcessor', '-encoding', 'utf8', 'C:\\Users\\MAHESH\\AppData\\Local\\Temp\\tmp1jcjvrl1']

Unable to use print_control_identifiers() for my desktop application in pywinauto

Hi I am unable to use the "print_control_identifiers()" for my desktop application.
I am using a) Python 3.5.3 (32 bit since my application I am automating is 32 bit)
b) Pywinauto 0.6.2.
My simple code is as follows:
`from pywinauto import Application
app = Application(backend="uia")
app = Application().start(r"C:\Program Files (x86)\Trane\TRACE 3D Plus\TRACE™ 3D Plus.exe")
app['TRACE™ 3D Plus'].print_control_identifiers()`
When I run the above command, I got the following in command prompt:
Traceback (most recent call last):
File "D:\Python\lib\site-packages\pywinauto\application.py", line 243, in __re
solve_control
criteria)
File "D:\Python\lib\site-packages\pywinauto\timings.py", line 424, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "inspect.py", line 4, in <module>
app['TRACE\u2122 3D Plus'].print_control_identifiers()
File "D:\Python\lib\site-packages\pywinauto\application.py", line 573, in prin
t_control_identifiers
this_ctrl = self.__resolve_control(self.criteria)[-1]
File "D:\Python\lib\site-packages\pywinauto\application.py", line 246, in __re
solve_control
raise e.original_exception
File "D:\Python\lib\site-packages\pywinauto\timings.py", line 402, in wait_unt
il_passes
func_val = func(*args)
File "D:\Python\lib\site-packages\pywinauto\application.py", line 188, in __ge
t_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**crite
ria[0]))
File "D:\Python\lib\site-packages\pywinauto\findwindows.py", line 84, in find_
element
elements = find_elements(**kwargs)
File "D:\Python\lib\site-packages\pywinauto\findwindows.py", line 294, in find
_elements
elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems
)
File "D:\Python\lib\site-packages\pywinauto\findbestmatch.py", line 534, in fi
nd_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'TRACE\u2122 3D Plus' in 'dic
t_keys([])'
Can anyone tell me what the problem is and what I could do to resolve it ?
Thanks in advance !
Replace these commands
app = Application(backend="uia")
app = Application().start(r"C:\Program Files (x86)\Trane\TRACE 3D Plus\TRACE™ 3D Plus.exe")
with this one:
app = Application(backend="uia").start(r'"C:\Program Files (x86)\Trane\TRACE 3D Plus\TRACE™ 3D Plus.exe"')
Because you re-create app object with default backend="win32" if not using any argument. If it's hard to understand, I'd recommend to get a Python course first. Basic Python programming skills is necessary here to understand what's going on.

py2app TypeError: dyld_find() got an unexpected keyword argument 'loader'

I'm having difficulty building my app using py2app. I can build it in alias mode without issue using this command:
python3.4 setup.py py2app -A
However when I try and build it using:
python3.4 setup.py py2app
I get the error message as per title of this post. From the research I've done I believe it's an issue with Pillow; however I need Pillow for this app. (Unless there's another module I can use to import images??). I've also tried cx_freeze without success.
Any help or direction much appreciated.
Full traceback as follows:
Traceback (most recent call last):
File "setup.py", line 19, in <module>
setup_requires=['py2app'],
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
distutils/core.py", line 148, in setup dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
distutils/dist.py", line 955, in run_commands self.run_command(cmd)
File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
distutils/dist.py", line 974, in run_command cmd_obj.run()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site- packages/py2app/build_app.py", line 659, in run self._run()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site- packages/py2app/build_app.py", line 865, in _run self.run_normal()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site- packages/py2app/build_app.py", line 959, in
run_normal self.create_binaries(py_files, pkgdirs, extensions,loader_files)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site- packages/py2app/build_app.py", line 1214, in create_binaries
platfiles = mm.run()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site-packages/macholib/MachOStandalone.py", line 105, in run
mm.run_file(fn)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site-packages/macholib/MachOGraph.py", line 84, in run_file
self.scan_node(m)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site-packages/macholib/MachOGraph.py", line 110, in scan_node
m = self.load_file(filename, caller=node)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site-packages/macholib/MachOGraph.py", line 93, in load_file
newname = self.locate(name, loader=caller)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site-packages/macholib/MachOStandalone.py", line 23, in locate
newname = super(FilteredMachOGraph, self).locate(filename, loader)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
site-packages/macholib/MachOGraph.py", line 49, in locate
loader=loader.filename)
TypeError: dyld_find() got an unexpected keyword argument 'loader'
This is a temporary solution, and it may break other things. I would recommend doing this is a virtual environment so you don't mess up your regular packages. This worked for me (virtenv is the name of my virtual environment)
Open the file /virtenv/lib/python3.4/site-packages/macholib/dyld.py and replace each instance of loader_path with loader. Now save and try again.
You can monkey-patch macholib rather than modifying it in site-packages. Place the following file to the directory containing setup_py2app.py and add import macholib_patch to the top.
macholib_patch.py:
"""
Monkey-patch macholib to fix "dyld_find() got an unexpected keyword argument 'loader'".
Add 'import macholib_patch' to the top of set_py2app.py
"""
import macholib
#print("~"*60 + "macholib verion: "+macholib.__version__)
if macholib.__version__ <= "1.7":
print("Applying macholib patch...")
import macholib.dyld
import macholib.MachOGraph
dyld_find_1_7 = macholib.dyld.dyld_find
def dyld_find(name, loader=None, **kwargs):
#print("~"*60 + "calling alternate dyld_find")
if loader is not None:
kwargs['loader_path'] = loader
return dyld_find_1_7(name, **kwargs)
macholib.MachOGraph.dyld_find = dyld_find

Resources