Python:Pycall Validation Error while Calling - python

I have Asterisk 13.20 set up and running fine on Ubuntu 16.04,calls are going well through a Softphone(Zoiper), I came across a Library in Python "Pycall" which lets you make calls through a Python Script.So I tried testing a snippet from the site Pycall
The code that I used:
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
Just made changes in the extension,wherein I used one from my server
However I am getting the following error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
c.spool()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 131, in spool
self.writefile()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 119, in writefile
f.write(self.contents)
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 114, in contents
return '\n'.join(self.buildfile())
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
raise ValidationError
pycall.errors.ValidationError
Tried searching online for the solution but coudnt find one,What am I doing wrong?

This question not related to PBX, it is just incorrect use of LIB.
General instruction how to solve ANY issue with availible source code.
You have error
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
Go that file and line, check code, add more debug if needed, fix your app.

Run as asterisk user.
sudo su asterisk -s /bin/bash
python
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()

Related

Impossible to retrieve data form pyattck module

I am using the pyattck module to retrieve information from mitre att&ck.
Versions:
- pyattck==7.0.0
- pyattck-data==2.5.2
Then, I just created a simple main.py file to test the module.
from pyattck import Attck
def main():
attck = Attck()
for technique in attck.enterprise.techniques:
print(technique.name)
if __name__ == '__main__':
main()
When running the main.py script I get the following exception:
Traceback (most recent call last):
File "/<path>/main.py", line 15, in <module>
main()
File "/<path>/main.py", line 8, in main
for technique in attck.enterprise.techniques:
File "/<path_venv>/lib/python3.10/site-packages/pyattck/attck.py", line 253, in enterprise
from .enterprise import EnterpriseAttck
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 7, in <module>
class EnterpriseAttck(Base):
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 42, in EnterpriseAttck
__attck = MitreAttck(**Base.config.get_data("enterprise_attck_json"))
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 55, in __init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 53, in __init__
self.__attrs_init__(**kwargs)
File "<attrs generated init pyattck_data.attack.MitreAttck>", line 14, in __attrs_init__
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 66, in __attrs_post_init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 62, in __attrs_post_init__
data = TYPE_MAP.get(item['type'])(**item)
TypeError: 'NoneType' object is not callable
Anyone knows where is the issue? Maybe I have forgotten to import something? It would be helpful to know if this module actually works in another version. This one is the lasted stable one ATTOW.
UPDATE
There is am issue with this project. Mitre added some new features that are not supported by the module and make it unusable.
There is an issue on github related to this.
They have already fixed this issue in future releases. You just need to update your package pyattck-data form the bugged version 2.5.2 to 2.6.1 (or any newer).
If you are using pip, just run this:
pip install --upgrade pyattck-data
If you are using conda (inside your venv):
conda update pyattck-data

CherryPy Python error "No such file or directory"

Im trying to run a python Server using CherryPy for a WebSite but when I run it this error pops up.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/cherrypy/_cprequest.py", line 638, in respond
self._do_respond(path_info)
File "/usr/local/lib/python3.10/dist-packages/cherrypy/_cprequest.py", line 694, in _do_respond
self.hooks.run('before_handler')
File "/usr/local/lib/python3.10/dist-packages/cherrypy/_cprequest.py", line 95, in run
self.run_hooks(iter(sorted(self[point])))
File "/usr/local/lib/python3.10/dist-packages/cherrypy/_cprequest.py", line 117, in run_hooks
hook()
File "/usr/local/lib/python3.10/dist-packages/cherrypy/_cprequest.py", line 65, in __call__
return self.callback(**self.kwargs)
File "/usr/local/lib/python3.10/dist-packages/cherrypy/_cptools.py", line 280, in _lock_session
cherrypy.serving.session.acquire_lock()
File "/usr/local/lib/python3.10/dist-packages/cherrypy/lib/sessions.py", line 550, in acquire_lock
self.lock = zc.lockfile.LockFile(path)
File "/usr/local/lib/python3.10/dist-packages/zc/lockfile/__init__.py", line 117, in __init__
super(LockFile, self).__init__(path)
File "/usr/local/lib/python3.10/dist-packages/zc/lockfile/__init__.py", line 87, in __init__
fp = open(path, 'a+')
FileNotFoundError: [Errno 2] No such file or directory: '/var/www/html/cncsessions\\/session-73ab2ecbe9bd50153b4f20828fcc08bff6e9cd6e.lock'
It's my first time using this module and I don't know what's wrong.
I'm using Ubuntu 22, Python 3.10.6
Hard to say without seeing your exact code that this is calling.
Judging by the Error you are trying to use Sessions.
The sessions are looking for
/var/www/html/cncsessions
To place the session files in
But it gives an error. It looks like the path might be wrong. There's a double backslash at the end there and a forward slash.
\\/
If you haven't given up on this/figured it out already I would try changing this path to just this
/var/www/html/cncsessions
Also be sure you do not store your session data in your web root. Looks like from that path you might be doing that! Anything in a webroot will be served via public webserver. There's little to no chance anyone would guess the file names though.

Assertion error on mininet-test experiment

My friend and I tried to reproduce this mininet-test experiment: https://github.com/mininet/mininet-tests/tree/master/dctcp
We self created a VM and installed Mininet 2.2 on ubuntu with kernel version 3.18.9, which included dctcp and tcp_probe function.
Since author suggest kernel version 3.0.1 didn't support those function we needed in Mininetnet. We simply changed the some function name in dctcp.py, such as: add_host changed to addHost, add_switch changed to addSwitch ,add_link changed to addLink.
And we also imported some python function we need, such as : python-matplotlib, python-termcolor and bwm-ng.
But we still encounter the following problems when we plotting the graph - cwnd.png.
Are we missing some important lib or any code need to change?
.Traceback (most recent call last):
File "dctcp.py", line 250, in <module>
main()
File "dctcp.py", line 244, in main
net.stop()
File "build/bdist.linux-x86_64/egg/mininet/net.py", line 514, in stop
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 479, in stop
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 472, in delete
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 199, in delete
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 64, in cmd
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 350, in cmd
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 269, in sendCmd
AssertionError
s1
s1-eth1
s1-eth2
s1-eth3
total
['tcp-n3-bw100/qlen_s1-eth1.txt']
I ran into this as well, and found that if you look at: https://github.com/bigswitch/mininet/blob/master/mininet/node.py and in the monitor() function section you will see that this function sets the waiting flag = False.
So the code can be
h1.sendCmd(startbackground_service)
h2.cmd(something_else)
h3.cmd(use_h1_service)
.....
#at some point end h1's background service, naturally or unnaturally
h1.monitor() # will check the service, and set waiting=False
For me h1.monitor() didn't worked in a similar situation on mininet 2.3.0 so I replaced the sendCmd() with popen() and then used the terminate() function.
Using the example above I changed it to:
p1 = h1.popen(startbackground_service)
h2.cmd(something_else)
h3.cmd(use_h1_service)
.....
p1.terminate()
The code seems to set a flag waiting at the end of a sendCmd() call, the flag is check to be False on every run of the method. It seem to be reset when the result of the command is received.
As the result you can't send a second command until the response of the first is received. This might just be a race condition but IMHO the library should handle that case in a more clever and transparent way.

fexpect breaks fabric scripts

I hot upon an requirement where I needed to automatically answer the prompt on remote machine and then I found fexpect after reading different stackoverflow questions. But the moment I include fexpect in my script it breaks the whole script!
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 743, in main
*args, **kwargs
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 368, in execute
multiprocessing
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 264, in _execute
return task.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 171, in run
return self.wrapped(*args, **kwargs)
File "/etc/puppet/fabfile.py", line 165, in edit_sudoers
run('echo "Current Permission of the file /etc/sudoers - "`stat -c "%a %n" /etc/sudoers`')
File "/usr/local/lib/python2.7/dist-packages/ilogue/fexpect/api.py", line 15, in run
wrappedCmd = wrapExpectations(cmd)
File "/usr/local/lib/python2.7/dist-packages/ilogue/fexpect/internals.py", line 15, in wrapExpectations
script = createScript(cmd)
File "/usr/local/lib/python2.7/dist-packages/ilogue/fexpect/internals.py", line 39, in createScript
for e in fabric.state.env.expectations:
File "/usr/local/lib/python2.7/dist-packages/fabric/utils.py", line 184, in __getattr__
raise AttributeError(key)
AttributeError: expectations
The moment i write
from ilogue.fexpect import expect, expecting, run fabric stops working with the above error message.
I asked in fabric irc as well but I got to know that this might be because of some version related issues. Has anyone else encountered this error before?
fexpect==0.2.post7
Fabric==1.8.0
Just import fexpect's run as erun and its sudo as esudo.
When you use the fexpect run or sudo functions, you must wrap those calls in a with expecting(prompts): context. This is a known issue in fexpect, although there is a pull request, so it might be fixed by the time posterity reads this.
One solution is to import fexpect's run function with a different name, e.g. erun, and use it only when you need the automatic prompt handling functionality:
from fabric.api import run
from ilogue.fexpect import expect, expecting, run as erun
run(a_cmd) # Native Fabric run - should work fine
prompts = [...]
with expecting(prompts):
erun(a_prompting_cmd) # fexpect run - should with fine inside expecting context
Another thing that isn't explicitly stated in the fexpect documentation is that the pexpect package needs to be installed on the target system.
Yet another fexpect gotcha is that the prompt strings are regular expressions -- the fexpect sample code is misleading about this.

ImportError: No localization support for language 'eng' in python

I am getting ImportError: No localization support for language 'eng' when using MySQL Connector in Python.
My Traceback is as below.
Traceback (most recent call last):
File \"DB_Module.py\", line 151, in QueryDatabase
File \"\\share\app\Modules\mysql\connector\__init__.py\", line 44, in Connect
File \"\\share\app\Modules\mysql\connector\connection.py\", line 106, in __init__
File \"\\share\app\Modules\mysql\connector\connection.py\", line 325, in connect
File \"\\share\app\Modules\mysql\connector\connection.py\", line 288, in _open_connection
File \"\\share\app\Modules\mysql\connector\network.py\", line 326, in open_connection
File \"\\sfs\show_time\Showtime_Package\showtime\Modules\mysql\connector\errors.py\", line 160, in __init__
File \"\\share\app\Modules\mysql\connector\locales\__init__.py\", line 52, in get_client_error
ImportError: No localization support for language 'eng'
And my Current used SQL is
SELECT * FROM systemdetails
WHERE System_ID = 'System1' LIMIT 1
Can anyone tell me how to fix this error?
In order for the MySql connector to print the actual error string - it needs the eng/client_error file in the "locales" dir.
I personally, just manually created the dir "eng" and copy-paste the file from this link:
http://pydoc.net/Python/mysql-connector-python/1.0.7/mysql.connector.locales.eng.client_error/
> mkdir eng
> touch eng/__init__.py
> vi eng/client_error.py
> ... copy-paste, save, and exit.
I run the code again, and received:
2013: Lost connection to MySQL server during query
You'll probably get a different error, but hope it helps.
Just put this to import the locale when you compile again with pyInstaller or py2exe.
from mysql.connector.locales.eng import client_error
They will include the modules needed to fix the error.
In my case, changing the latest mysql.connector module to a former version solved the problem. I changed the version from 8.0.30 to 8.0.17.

Categories