name 'OSPF_Link' is not defined - python

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....

Related

"Module not found error" while trying to call a function that is in another directory

Trying to call a function yamlCreation() which is in another directory into this python file ..
the path of this file is
path:bss_micro_svcs/bss_micro_svcs/kubectl.py
Calling File: "kubectl.py"
from bss_micro_svcs.kubectl_utils.templating_to_yaml import yamlCreation
class Kube(Svcs):
def startService(self, cluster_info, service, service_profile):
yamlCreation()
k=Kube()
k.startService()
yamlCreation() function is in this python file named "templating_to_yaml.py"
the path of the file is..
path:bss_micro_svcs/kubectl_utils/templating_to_yaml.py
function to be called is inside this file:"templating_to_yaml.py"
file_loader = FileSystemLoader('bss_micro_svcs/bss_micro_svcs/yamls/templates')
env = Environment(loader=file_loader)
#deployment.yaml templating
deployment_template=env.get_template('deployment.tmpl')
deployment_output=deployment_template.render(deployment_name='nginx-deployment',deployment_app='nginx',deployment_replicas='3',deployment_container_name='nginx',deployment_image='nginx:1.14.2',deployment_container_port=80)
deployment_outfile=open('bss_micro_svcs/bss_micro_svcs/yamls/services/integration/deployment.yaml','w')
deployment_outfile.write(deployment_output)
deployment_outfile.close()
#*********************************************************************************************************************************************************#
#service.yaml templating
service_template=env.get_template('services.tmpl')
service_output=service_template.render(service_name='integration-service',service_name_space='demo-sandbox',service_app='integration',service_port=8090,target_port=8090)
service_outfile=open('bss_micro_svcs/bss_micro_svcs/yamls/services/integration/services.yaml','w')
service_outfile.write(service_output)
service_outfile.close()
GETTING AN ERROR:
┌──(bss_micro_svcs-jnO67Li7)(RK㉿kali)-[~/Desktop/servicelaunchmgr]
└─$ /home/RK/.local/share/virtualenvs/bss_micro_svcs-jnO67Li7/bin/python /home/RK/Desktop/servicelaunchmgr/bss_micro_svcs/bss_micro_svcs/kubectl.py
Traceback (most recent call last):
File "/home/RK/Desktop/servicelaunchmgr/bss_micro_svcs/bss_micro_svcs/kubectl.py", line 2, in <module>
from bss_micro_svcs.kubectl_utils.templating_to_yaml import yamlCreation
ModuleNotFoundError: No module named 'bss_micro_svcs'
You could set environment variable PYTHONPATH so the interpreter could know where to start looking for the module to import. I would suggest to set it in the root module.
Reference: https://bic-berkeley.github.io/psych-214-fall-2016/using_pythonpath.html

How run package Depix?

I'm new to Python and I want to run the Duplex tool (https://github.com/beurtschipper/Depix ). But the test version does not start, when I type an in the command line:
python depix.py -p images/testimages/testimage3_pixels.png -s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png -o output.png
an error occurs:
Traceback (most recent call last):
File "F:\Work\Projects\Python\Depix\Depix-main\depixlib\depix.py ", line 10, in <module>
from. import __version__
Error Importer error: an attempt at relative import without a known parent package
In the READMI written
sh
depix \
-p /path/to/your/input/image.png \
-s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png \
-o /path/to/your/output.png
But I do not know how to run it, please help
I had the same error and it looks like it is a directory structure problem.
You can fix it by adding depixlib where you import the modules.
depixlib\depix.py
from depixlib import __version__
from depixlib.functions import
from depixlib.LoadedImage import LoadedImage
from depixlib.Rectangle import Rectangle
Hope it fixed your problem!
Now, I get the following errors, but that's another story. 😅
LoadedImage.py
return cast(list[list[tuple[int, int, int]]], _imageData)
TypeError: 'type' object is not subscriptable
edit: Actually I fixed the above by changing the following line to:
Last line of LoadedImage.py file
return cast(list(list([int, int, int])), _imageData)
It was mentionned here: https://github.com/beurtschipper/Depix/pull/83
Cheers!

Getting "global name 'FbxManager' is not defined"

I am working on creating a WebGL interface for which I am trying to convert FBX models to JSON file format in an automated process using python file, convert_fbx_three.py (from Mr. Doob's GitHub project) from command line.
When I try the following command to convert the FBX:
python convert_fbx_three.py Dolpine.fbx Dolpine
I get following errors:
Error in cmd:
Traceback (most recent call last):
File "convert_fbx_three.py", line 1625, in <module>
sdkManager, scene = InitializeSdkObjects()
File "D:\xampp\htdocs\upload\user\fbx\FbxCommon.py", line 7, in InitializeSdkObjects
lSdkManager = KFbxSdkManager.Create()
NameError: global name 'FbxManager' is not defined
I am using Autodesk FBX SDK 2012.2 available here on Windows 7.
Can you please try the following:
import FbxCommon
.
.
.
lSdkManager, lScene = FbxCommon.InitializeSdkObjects()
You probably need to add environment variables pointing to the folder that contains fbx.pyd, FbxCommon.py, and fbxsip.pyd prior to calling anything in those modules.

Python: Run Script Under Same Window

I am trying to setup a program where when someone enters a command it will run that command which is a script in a sub folder called "lib".
Here is my code:
import os
while 1:
cmd = input(' >: ')
for file in os.listdir('lib'):
if file.endswith('.py'):
try:
os.system(str(cmd + '.py'))
except FileNotFoundError:
print('Command Not Found.')
I have a file: lib/new_user.py But when I try to run it I get this error:
Traceback (most recent call last):
File "C:/Users/Daniel/Desktop/Wasm/Exec.py", line 8, in <module>
exec(str(cmd + '.py'))
File "<string>", line 1, in <module>
NameError: name 'new_user' is not defined
Does anyone know a way around this? I would prefer if the script would be able to be executed under the same window so it doesn't open a completely new one up to run the code there. This may be a really Noob question but I have not been able to find anything on this.
Thanks,
Daniel Alexander
os.system(os.path.join('lib', cmd + '.py'))
You're invoking new_user.py but it is not in the current directory. You need to construct lib/new_user.py.
(I'm not sure what any of this has to do with windows.)
However, a better approach for executing Python code from Python is making them into modules and using import:
import importlib
cmd_module = importlib.import_module(cmd, 'lib')
cmd_module.execute()
(Assuming you have a function execute defined in lib/new_user.py)

Python 3.1 - Error while adding a library in Blender

For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I get this error now:
Traceback (most recent call last):
File "websocket.py", line 6, in
AttributeError: 'module' object has no attribute 'WebSocket'
when running this code in Blender:
import sys, os, asyncore, websocket
def msg_handler(msg):
print(msg)
socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler)
socket.onopen = lambda: socket.send('Hello world!')
try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
I found that a __init__.py is needed so I added but it didn't help…
What I am doing wrong here ? Thanks for your help.
It looks like you called your script websocket.py, so the import of websocket finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc file, delete that.)

Categories