pysnmp not loading MIB - snmp

I have two MIBS files, MIB1 and MIB2, MIB2 is importing elements from MIB1. I've run smilint and build-pysnmp-mib, actually smidump as I was not be able to pre-load the file exporting elements with build-pysnmp-mib.
With smidump I have two MIB .py modules, MIB1.py and MIB2.py, however when I write my SNMP agent, pysnmp is not able to find MIB1.py exporting module. I got this error
Traceback (most recent call last):
File "snmpagent.py", line 165, in <module>
agent = SNMPAgent(objects)
File "snmpagent.py", line 90, in __init__
mibObject.objectType)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 299, in importSymbols
self.loadModules(modName, **userCtx)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules
'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.SmiError: MIB module "./MIB2.py" load error: ['Traceback (most recent call last):\n', ' File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\n exec(modData, g)\n', ' File "<string>", line 17, in <module>\n', ' File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 302, in importSymbols\n \'No module %s loaded at %s\' % (modName, self)\n', 'SmiError: No module MIB1 loaded at <pysnmp.smi.builder.MibBuilder instance at 0x7f99213c0b48>\n']
I have tried updating SMIPATH, and also loading manually the .py module with
mibPath = mibBuilder.getMibSources() + (builder.DirMibSource('path'),)
mibBuilder.setMibSources(*mibPath)
mibBuilder.loadModules(
'MIB1',
)
I'm running pysnmp on Ubuntu 14.04 and Python 2.7.6.
Can anybody help me out on this?

Please use mibdump.py tool from the pysmi package to compile ASN.1 MIBs into Python/pysnmp module. That tool will handle all the dependencies and produce much better MIBs. Generated MIBs are backward compatible with all previous pysnmp versions. The pysmi package runs on Python 2 & 3 out-of-the-box.
Since pysnmp 4.3, no explicit ASN.1 MIB compilation step is required -- pysnmp 4.3+ will automatically invoke pysmi to find/download/compile ASN.1 MIB and hand it over to pysnmp.
It is always better to upgrade to the latest pysnmp whenever possible.

Related

failed to import pywin32 (even if it already installed) while starting supervisord in windows nanoserver container

I am trying to bring two process up in a windows Nanoserver container using supervisord (pip install supervisor-win )
Everything is setup in supervisord.conf, while starting it I am facing below issue,
C:\data>supervisord -n
C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\options.py:480: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (inc
luding its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
self.warnings.warn(
Traceback (most recent call last):
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\loggers.py", line 220, in _disable_inheritance_filehandler
import win32api
oduleNotFoundError: No module named 'win32api'
D
uring handling of the above exception, another exception occurred:
T
raceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\python-3.11.1-embed-amd64\Scripts\supervisord.exe\__main__.py", line 7, in <module>
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\supervisord.py", line 403, in main
go(options)
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\supervisord.py", line 415, in go
d.main()
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\supervisord.py", line 77, in main
self.options.make_logger()
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\options.py", line 1221, in make_logger
loggers.handle_file(
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\loggers.py", line 444, in handle_file
handler = RotatingFileHandler(filename, 'a', maxbytes, backups)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\loggers.py", line 211, in __init__
self._disable_inheritance_filehandler() # fix file used by others process
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\python-3.11.1-embed-amd64\Lib\site-packages\supervisor\loggers.py", line 223, in _disable_inheritance_filehandler
raise ImportWarning("log rotation requires the installation of the \"pywin32\" library.\n"
ImportWarning: log rotation requires the installation of the "pywin32" library.
Download and install from https://github.com/mhammond/pywin32/releases
C:\data>
pywin32 module is already installed (tried reinstall with whl and pip anyway, that did not help)
C:\data>python -m pip show pywin32
Name: pywin32
Version: 305
Summary: Python for Window Extensions
Home-page: https://github.com/mhammond/pywin32
Author: Mark Hammond (et al)
Author-email: mhammond#skippinet.com.au
License: PSF
Location: C:\python-3.11.1-embed-amd64\Lib\site-packages
Requires:
Required-by: pypiwin32, supervisor-win
C:\data>
What could be the issue here? I see less dll files (around 400 only) in C:\Windows\System32 compared to servercore/server image (This is working fine with windows servercore image.)

YFinance JSONDecodeError--latest version

When I tried to dowload historic data, I get the following error message:
Exception in thread Thread-6:
Traceback (most recent call last):
File "E:\Anaconda\envs\finrl\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "E:\Anaconda\envs\finrl\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "E:\Anaconda\envs\finrl\lib\site-packages\multitasking\__init__.py", line 104, in _run_via_pool
return callee(*args, **kwargs)
File "E:\Anaconda\envs\finrl\lib\site-packages\yfinance\multi.py", line 169, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "E:\Anaconda\envs\finrl\lib\site-packages\yfinance\multi.py", line 181, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "E:\Anaconda\envs\finrl\lib\site-packages\yfinance\base.py", line 162, in history
data = data.json()
File "E:\Anaconda\envs\finrl\lib\site-packages\requests\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "E:\Anaconda\envs\finrl\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "E:\Anaconda\envs\finrl\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "E:\Anaconda\envs\finrl\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
here is my code:
import yfinance as yf
data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")
I have tried many methods:
install the latest version of yfinance
install the old version of yfinance
revise the code
In fact, when I use yahoo_fin, the same error occurs too.
Wish someone to help me solve this problem
your code is correct.
This is happening because Anaconda is used to simulate an environment so packets have determined versions so that everything is compatible. The thing that happens in your case is that yfinance is older and your version of JSON is not compatible with some functions of yfinance since yfinance is no anymore updated.
I recommend you to just install on your computer with pip the packet yfinance as follows instead of using the environment of anaconda:
pip install yfinance
and then it should try to get the correct versions of the libraries that it needs. After that, you can create a python file and then import the packet
import yfinance as yf
and then execute your download code
data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")
As a recommendation, try to pass different values as a list instead of a string, because it will be hard to debug later. Instead of "SPY AAPL" -> ['SPY', 'AAPL']
Edit: Also it can be that your finance version is YEARS old (but I don't think so), is this is the case then you should try to update inside of the anaconda updater. Otherwise, with the terminal, it would be something like:
pip install yfinance --upgrade

Pyusb and Libusb giving NoBackendError on MacOS

I'm on MacOS Big Sur trying to run rfcat. I am running anaconda as well and I have set up an environment with Python2.7 when I originally got errors with Python3.x. I have downloaded the pyusb, pyreadline, ipython, PySide2, and the libusb dependancies. Libusb seems to be giving me the most trouble. I keep getting the following error:
Error in resetup():NoBackendError('No backend available',)
Error in resetup():NoBackendError('No backend available',)
Error in resetup():NoBackendError('No backend available',)
^CTraceback (most recent call last):
File "/opt/anaconda3/envs/rftools/bin/rfcat", line 4, in <module>
__import__('pkg_resources').run_script('rfcat==1.9.5', 'rfcat')
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1469, in run_script
exec(script_code, namespace, namespace)
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/rfcat-1.9.5-py2.7.egg/EGG-INFO/scripts/rfcat", line 63, in <module>
File "build/bdist.macosx-10.7-x86_64/egg/rflib/__init__.py", line 208, in interactive
File "build/bdist.macosx-10.7-x86_64/egg/rflib/chipcon_nic.py", line 103, in __init__
File "build/bdist.macosx-10.7-x86_64/egg/rflib/chipcon_usb.py", line 93, in __init__
File "build/bdist.macosx-10.7-x86_64/egg/rflib/chipcon_usb.py", line 238, in resetup
KeyboardInterrupt
From my research so far, backend is how pyusb refers to libusb, libusb1 or openusb. It is unable to find the libusb within the environment. I did a little tracking and found that ultimately, the find_library() function is found in ctypes in util.py. It refers to the executable path for MacOS with #executable_path/../lib/libusb%s..... I tried to put libusb into a folder on my executable path to hopefully match this functions search, and still got the same errors. I then found instructions on inputting a custom path for the backend for pyusb here. This appears to be a method where you input the device and backend information at the beginning of your program. The code I inserted is as follows:
import usb.core
import usb.backend.libusb1 as libusb1
backend = libusb1.get_backend(find_library=lambda x: "/path/to/file/lib/libusb-1.0.0.dylib")
dev = usb.core.find(idVendor=“MyVID”, idProduct=“MyPID”, backend=backend)
This induced a similar error but with a different traceback when I placed the code in rflib.init and the rfcat codes:
Traceback (most recent call last):
File "/opt/anaconda3/envs/rftools/bin/rfcat", line 4, in <module>
__import__('pkg_resources').run_script('rfcat==1.9.5', 'rfcat')
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1469, in run_script
exec(script_code, namespace, namespace)
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/rfcat-1.9.5-py2.7.egg/EGG-INFO/scripts/rfcat", line 12, in <module>
File "build/bdist.macosx-10.7-x86_64/egg/rflib/__init__.py", line 15, in <module>
File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/usb/core.py", line 1304, in find
raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available
I have since reset things back to how I started and am still getting the original error listed above.
I think this largely has to do with the anaconda environment, which I can of course remove. I want to try to find a way to make this work though. Is there a better method to help rfcat find the libusb as required? Another possible solution is resolving the actual executable_path. Does anyone know how to find the executable_path?
In case it helps, I will list the default locations for commands and files.
rfcat: /opt/anaconda3/envs/rftools/lib/python2.7/site-packages/rfcat
pyusb: /opt/anaconda3/envs/rftools/lib/python2.7/site-packages/usb
ctypes: /opt/anaconda3/envs/rftools/lib/python2.7/ctypes
libusb: /opt/anaconda3/envs/rftools/lib/python2.7/site-packages/usb/lib

Not able to run basic example of pycparser

I am trying to start with pycparser and was trying to run the examples given on the github repo. I only changed the path of the file to be parsed after saving the sample c file locally. I get the following error and am not sure if there is some pre-processing step that I am missing?
File "D:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
execfile(filename, namespace)
File "D:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Z003RTRP/Desktop/cparse.py", line 20, in <module>
ast = parse_file(filename, use_cpp=True, cpp_path='gcc', cpp_args=r'-Iutils/fake_libc_include')
File "D:\Anaconda3\lib\site-packages\pycparser\__init__.py", line 86, in parse_file
text = preprocess_file(filename, cpp_path, cpp_args)
File "D:\Anaconda3\lib\site-packages\pycparser\__init__.py", line 49, in preprocess_file
('Original error: %s' % e))
RuntimeError: Unable to invoke 'cpp'. Make sure its path was passed correctly
Original error: [WinError 2] The system cannot find the file specified
Take a look at this section of the README - you have to point cpp_path to the C preprocessor on your system. For Windows, it recommends downloading a binary build of Clang and using clang -E

Error with gclient sync while getting the chromium code on Mac OS

I'm trying to setup the chromium code following the documentation on Mac OS X 10.9.2.
I could successfully fetch the code with command:
fetch --nohooks chromium --nosvn=True
but when I try to sync the projects with gclient sync command it's breaking in the middle of the process throwing the following OSError:
________ running '/usr/bin/python src/build/download_nacl_toolchains.py --no-arm-trusted --keep' in '/Volumes/NJHD/google'
Updating /Volumes/NJHD/google/src/native_client/toolchain/.tars/toolchain_mac_x86.tar.bz2
from https://storage.googleapis.com/nativeclient-archive2/x86_toolchain/r12790/toolchain_mac_x86.tar.bz2.
.....................................................................................
|------------------------------------------------|
..................................................Traceback (most recent call last):
File "src/build/download_nacl_toolchains.py", line 63, in <module>
sys.exit(Main(sys.argv[1:]))
File "src/build/download_nacl_toolchains.py", line 58, in Main
download_toolchains.main(args)
File "/Volumes/NJHD/google/src/native_client/build/download_toolchains.py", line 414, in main
keep=options.keep, verbose=options.verbose):
File "/Volumes/NJHD/google/src/native_client/build/download_toolchains.py", line 263, in SyncFlavor
tar.Extract()
File "/Volumes/NJHD/google/src/native_client/build/cygtar.py", line 313, in Extract
self.tar.extract(m)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 2084, in extract
self._extract_member(tarinfo, os.path.join(path, tarinfo.name))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 2168, in _extract_member
self.makelink(tarinfo, targetpath)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 2252, in makelink
os.link(tarinfo._link_target, targetpath)
OSError: [Errno 45] Operation not supported
Error: Command /usr/bin/python src/build/download_nacl_toolchains.py --no-arm-trusted --keep returned non-zero exit status 1 in /Volumes/NJHD/google
Hook '/usr/bin/python src/build/download_nacl_toolchains.py --no-arm-trusted --keep' took 89.91 secs
It seems to me that it is complaining about os.link(tarinfo._link_target, target path), so I tried creating a link using that function which works fine.
Is there any other configuration that I need to take care of?
Thanks in advance!
I placed the chromium project on an external hard disk as you did, and I got the same error.
Perhaps you should try the syncing stuff in your internal drive.
Haven't tried. Hope that help.

Resources