I have installed pysnmp-4.x.I am getting following error during running a SNMP program.
I am using pysnmpSE 3.5.2 now but getting same error. I found that pysnmpSE doesn't hav v4 module. I was suggested that following error should resolved if pySNMP SE 3.x is used.
Traceback (most recent call last):
File "C:\Documents and Settings\ggne0622\Desktop\Python\google-python-exercises\babynames\SimpleAgent.py", line 18, in <module>
from twistedsnmp import agent, agentprotocol, bisectoidstore
File "C:\Python27\Lib\site-packages\twistedsnmp\agent.py", line 4, in <module>
from twistedsnmp import datatypes
File "C:\Python27\Lib\site-packages\twistedsnmp\datatypes.py", line 7, in <module>
from twistedsnmp.pysnmpproto import v2c,v1
File "C:\Python27\Lib\site-packages\twistedsnmp\pysnmpproto.py", line 13, in <module>
from pysnmp.v4.proto.omni import v2c,v1, error, rfc1157, rfc1905
ImportError: No module named v4.proto.omni
Code:
#!/usr/bin/env python
from twisted.internet.iocpreactor import reactor
from twisted.internet import error as twisted_error
from twistedsnmp import agent, agentprotocol, bisectoidstore
#from twisted.internet import interfaces
try:
from twistedsnmp import bsdoidstore
except ImportError:
import warnings
warnings.warn( """No BSDDB OID Storage available for testing""" )
bsdoidstore = None
def createAgent( oids ):
ports = [161]+range(20000,25000)
for port in ports:
try:
`agentObject = reactor.IOCPReactor.listenUDP(port,` `agentprotocol.AgentProtocol(snmpVersion = 'v2c',agent = agent.Agent(dataStore =` `bisectoidstore.BisectOIDStore(OIDs = oids,),),),)`
`except twisted_error.CannotListenError:`
`pass`
`else:`
`return agentObject, port`
testingOIDs = {
'.1.3.6.1.2.1.1.1.0': 'Some tool out in the field',
'.1.3.6.1.2.1.1.2.0': '.1.3.6.1.4.1.88.3.1',
'.1.3.6.1.2.1.1.3.0': 558566090,
'.1.3.6.1.2.1.1.4.0': "support#somewhere.ca",
'.1.3.6.1.2.1.1.5.0': "NameOfSystem",
'.1.3.6.1.2.1.1.6.0': "SomeHeadEnd, West Hinterlands, Canada",
}
def main(oids=testingOIDs):
agent, port = createAgent( oids )
if __name__ == "__main__":
reactor.IOCPReactor.callWhenRunning( main )
reactor.IOCPReactor.run()
TwistedSNMP does not seem to be designed to work with PySNMP 4.x. Thus you should either use PySNMP 3.x / PySNMP SE or switch to PySNMP 4.x which has its own Twisted binding.
Related
i am recently learning python so this is my code
import firebase
firebase = firebase.FirebaseApplication("https://cleandzapp.firebaseio.com/")
data ={
'Name': 'nana',
'Email':'ghjjkk',
}
result = firebase.post('cleandzapp/student',data)
print(result)
and this is the error i got
C:\Users\Marc\PycharmProjects\pythonProject\venv\Scripts\python.exe "C:\Data\nana\studY\CS\2CS\S2\arduino\mini projet\CleanDzApp\firebase_test.py"
Traceback (most recent call last):
File "C:\Data\nana\studY\CS\2CS\S2\arduino\mini projet\CleanDzApp\firebase_test.py", line 1, in <module>
import firebase
File "C:\Users\Marc\PycharmProjects\pythonProject\venv\lib\site-packages\firebase\__init__.py", line 19, in <module>
from sseclient import SSEClient
ModuleNotFoundError: No module named 'sseclient'
Process finished with exit code 1
the initial problem has that solution ___>the async became a key word in the latest versions of pip so you should change the file async in this path C:\Users\username\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\firebase into something else like nasync , also change the ---- from sync import process pool---- in init.py and firebase.py (in the same path) into to ---- from nsync import process pool---- , that should solve the problem
I have a Python API running on Google's Cloud Endpoints framework.
I'm trying to implement a runner for my unittests, using the dev_appserver.
I've copied and adapted what Google is offering about this, just edited a bit to make it run the devappserver all-in-one.
This is what I've done so far:
import argparse
import os
import sys
import unittest
def fixup_paths(path):
"""Adds GAE SDK path to system path and appends it to the google path
if that already exists."""
try:
import google
google.__path__.append("{0}/google".format(path))
except ImportError:
pass
sys.path.insert(0, path)
def main(sdk_path, test_path, test_pattern):
# If the SDK path points to a Google Cloud SDK installation
# then we should alter it to point to the GAE platform location.
if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')):
sdk_path = os.path.join(sdk_path, 'platform/google_appengine')
# Make sure google.appengine.* modules are importable.
fixup_paths(sdk_path)
# Make sure all bundled third-party packages are available.
import dev_appserver
dev_appserver.fix_sys_path()
# Fix google shits
from google.appengine.tools.devappserver2 import devappserver2
# Start the devappserver
server_instance = devappserver2.DevelopmentServer()
server_instance.start()
# Discover and run tests.
suite = unittest.loader.TestLoader().discover(test_path, test_pattern)
suite_result = unittest.TextTestRunner(verbosity=2).run(suite)
server_instance.stop()
return suite_result
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'sdk_path',
help='The path to the Google App Engine SDK or the Google Cloud SDK.')
parser.add_argument(
'--test-path',
help='The path to look for tests, defaults to the current directory.',
default=os.getcwd())
parser.add_argument(
'--test-pattern',
help='The file pattern for test modules, defaults to *_test.py.',
default='test_*.py')
args = parser.parse_args()
result = main(args.sdk_path, args.test_path, args.test_pattern)
if not result.wasSuccessful():
sys.exit(1)
But i'm struggling with a strange import error.
I've been searching through Github but I was unable to find anything:
Traceback (most recent call last):
File "runner.py", line 65, in <module>
result = main(args.sdk_path, args.test_path, args.test_pattern)
File "runner.py", line 34, in main
from google.appengine.tools.devappserver2 import devappserver2
File "/Users/toto/Libraries/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 27, in <module>
from google.appengine.tools.devappserver2 import api_server
File "/Users/toto/Libraries/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 79, in <module>
from google.appengine.tools.devappserver2 import wsgi_server
File "/Users/toto/Libraries/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 48, in <module>
from cherrypy import wsgiserver
File "/usr/local/lib/python2.7/site-packages/cherrypy/__init__.py", line 73, in <module>
from ._cptools import default_toolbox as tools, Tool
File "/usr/local/lib/python2.7/site-packages/cherrypy/_cptools.py", line 33, in <module>
from cherrypy.lib import auth_basic, auth_digest
File "/usr/local/lib/python2.7/site-packages/cherrypy/lib/auth_digest.py", line 27, in <module>
from six.moves.urllib.request import parse_http_list, parse_keqv_list
ImportError: cannot import name parse_http_list
I can't figure out how to fix that import thing :(
The error means that the package six you have installed does not include parse_http_list. Try upgrading the six package:
pip install six==1.14.0
It could be that the parent package then throws an error, then upgrade that package as well.
Getting following error when running python script for web
Traceback (most recent call last):
File "SampleWSTest.py", line 10, in <module>
from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter
File "C:\Python27\lib\site-packages\web\wsgiserver\ssl_builtin.py", line 14, in <module>
from cherrypy import wsgiserver
ImportError: cannot import name wsgiserver
Running on python 2.7.15
import web
import sys
import argparse
import traceback
from web.wsgiserver import CherryPyWSGIServer
from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter
from OpenSSL import SSL
class Healthcheck:
def GET(self):
return 'Yassssssssss !!!!!'
URLS = ('/svc/healthcheck', 'Healthcheck')
CherryPyWSGIServer.ssl_certificate = 'alice.crt'
CherryPyWSGIServer.ssl_private_key = 'alice.key'
if __name__ == '__main__':
CherryPyWSGIServer.ssl_adapter = BuiltinSSLAdapter(CherryPyWSGIServer.ssl_certificate, CherryPyWSGIServer.ssl_private_key)
CherryPyWSGIServer.ssl_adapter.context = SSL.Context(SSL.SSLv23_METHOD)
CherryPyWSGIServer.ssl_adapter.context.set_options(SSL.OP_NO_SSLv3)
CherryPyWSGIServer.ssl_adapter.context.use_certificate_file(CherryPyWSGIServer.ssl_certificate)
CherryPyWSGIServer.ssl_adapter.context.use_privatekey_file(CherryPyWSGIServer.ssl_private_key)
app = web.application(URLS, globals())
app.run()
This started failing after we had to disable ssl 2 and ssl 3 so had to add ssl_adapter but BuiltinSSLAdapter fails with the import.
If any other alternatives please suggest. Basically want to disable ssl 2 and ssl 3 previously we didnt have from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter
from OpenSSL import SSL
CherryPy moved wsgiserver to cheroot in 2017.
http://docs.cherrypy.dev/en/latest/history.html#v9-0-0
So now you need to import it like this:
from cheroot.wsgi import Server as CherryPyWSGIServer
or rename it throughout.
I have a twisted tac file (twisted_service.py) with a code:
from twisted.application import service
# application.py file in the same dir
from .application import setup_reactor
class WebsocketService(service.Service):
def startService(self):
service.Service.startService(self)
setup_reactor()
application = service.Application("ws")
ws_service = WebsocketService()
ws_service.setServiceParent(application)
Here is application.py file, which sets up the reactor:
# -*- coding: utf-8 -*-
from twisted.web.server import Site
from twisted.web.static import Data
from twisted.internet import reactor, defer
from autobahn.twisted.resource import WebSocketResource
from autobahn.twisted.websocket import WebSocketServerFactory
from txsni.snimap import SNIMap
from txsni.maputils import Cache
from txsni.snimap import HostDirectoryMap
from twisted.python.filepath import FilePath
from tools.database.async import pg_conn
from tools.database import makedsn
from tools.config import main_db
from tools.modules.external import flask_setup
import tools.config as config
import websockethandlers as wsh
from pytrapd import TrapsListener
PROTOCOLMAP = {
'portcounters': wsh.PortCounters,
'eqcounters': wsh.EquipmentCounters,
'settings': wsh.Settings,
'refresh': wsh.Refresher,
'montraps': wsh.TrapsMonitoring,
'fdbs': wsh.FdbParser,
'portstate': wsh.PortState,
'cable': wsh.CableDiagnostic,
'eqcable': wsh.EquipmentCableDiagnostic,
'igmp': wsh.Igmp,
'ipmac': wsh.IpMac,
'lldp': wsh.LLDPParser,
'alias': wsh.AliasSetup,
'ping': wsh.Ping
}
#defer.inlineCallbacks
def setup_reactor():
flask_setup()
yield pg_conn.connect(makedsn(main_db))
root = Data("", "text/plain")
for key in PROTOCOLMAP:
factory = WebSocketServerFactory("wss://localhost:%s" % config.ws_port)
factory.protocol = PROTOCOLMAP[key]
resource = WebSocketResource(factory)
root.putChild(key, resource)
site = Site(root)
context_factory = SNIMap(
Cache(HostDirectoryMap(FilePath(config.certificates_directory)))
)
reactor.listenSSL(config.ws_port, site, context_factory)
traps_listener = TrapsListener()
traps_listener.listen_traps(config.trap_ip)
traps_listener.listen_messages(config.fifo_file)
if __name__ == '__main__':
setup_reactor()
import sys
from twisted.python import log
log.startLogging(sys.stdout)
reactor.run()
I use twistd -noy twisted_service.py command to run the twisted service. It has been working for twisted 16.3.2 version. After upgrade to any next version I got the error:
Unhandled Error
Traceback (most recent call last):
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/application/app.py", line 662, in run
runApp(config)
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/scripts/twistd.py", line 25, in runApp
_SomeApplicationRunner(config).run()
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/application/app.py", line 380, in run
self.application = self.createOrGetApplication()
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/application/app.py", line 445, in createOrGetApplication
application = getApplication(self.config, passphrase)
--- <exception caught here> ---
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/application/app.py", line 456, in getApplication
application = service.loadApplication(filename, style, passphrase)
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/application/service.py", line 412, in loadApplication
application = sob.loadValueFromFile(filename, 'application')
File "/home/kalombo/.virtualenvs/dev/local/lib/python2.7/site-packages/twisted/persisted/sob.py", line 177, in loadValueFromFile
eval(codeObj, d, d)
File "twisted_service.py", line 3, in <module>
from .application import setup_reactor
exceptions.ImportError: No module named application
How should I run the twisted or import module properly?
What the answer I found nearly yours. like the follows:
import os
import sys
sys.path = [os.path.join(os.getcwd(), '.'), ] + sys.path
just add the current working directory to the sys.path.
But I have not found more better method.... I think this not very good.
I found the answer here http://twistedmatrix.com/pipermail/twisted-python/2016-September/030783.html
It is a new feature in Twisted 16.4.0. In previous versions twistd script automatically added working dir to system paths, from 16.4.0 version i have to added it manually. It can be added something like this in twisted_service.py file:
import os
import sys
TWISTED_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(TWISTED_DIR)
I am using the following code to sign in to twitter:
import simplejson
import twitter
import oauth
import oauthtwitter
from oauthtwitter import OAuthApi
class OauthRequest():
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
AUTHORIZATION_URL = 'http://twitter.com/oauth/authorize'
REQUEST_TOKEN_URL = 'https://twitter.com/oauth/request_token'
def GetRequest(self):
vOauthApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET)
self.mOauthRequestToken = vOauthApi.getRequestToken(self.REQUEST_TOKEN_URL)
self.mOauthRequestUrl = vOauthApi.getAuthorizationURL(self.mOauthRequestToken)
However, I receive the following error message:
Traceback (most recent call last):
File "C:\Python33\twitter.py", line 4, in <module>
import oauthtwitter
File "C:\Python33\lib\site-packages\oauthtwitter.py", line 17, in <module>
from twitter import Api, User
ImportError: cannot import name Api
I have installed PIP and downloaded the 'oauth', 'oauthtwitter' and 'twitter' modules using it. I am running Windows Vista and Python 3.3. As far as I can tell in my 'Lib' folder the files are there for oauthtwitter.
I'm noy sure exactly what is going wrong here?
Thanks