<BEA-050001> <WLContext.close() was called in a different thread than the one in which it was created.> - weblogic

Unable to activate the changes when I deploy multiple ears through WLST script. The error is as below and unable to activate the changes.
WLSTException: Error occurred while performing activate : Error while Activating changes. : weblogic.application.ModuleException: Context path '/deployment' is already in use by the module: deployment application: my.ear
My script is:
import os
import sys
import java
def connectAdmin() :
print('connecting to the url:')
try:
connect(username, password, url)
print('Successfully connected')
except:
print 'Unable to find admin server...'
exit()
def deployApplication() :
directory='D:/AMSP/VerCrossCorp/Srinivas/DOMAIN_HOME/amspv97-9709-wl12/servers/AdminServer/deployment'
for filename in os.listdir(directory):
if filename.endswith(".war") or filename.endswith(".ear"):
progress=deploy(filename,directory,targets='AdminServer')
if __name__== "main":
print 'starting the script ....'
username = 'weblogic'
password = 'weblogic'
url='t3://172.27.49.161:9709'
connectAdmin()
edit()
startEdit()
deployApplication()
activate()
disconnect()

Related

How to create a custom Ambari alert dispatcher

I am trying to create an alert notification on ambari choosing alert script as method. Here are the steps I have followed:
Create an alert target using Create Alert Notification screen
{
"AlertTarget":
{
"name": "test_dispatcher",
"description": "Custom Notification Dispatcher",
"notification_type": "ALERT_SCRIPT",
"global": true,
"alert_states": ["CRITICAL","WARNING","UNKNOWN","OK"],
"properties": {
"ambari.dispatch-property.script": "notification.dispatch.alert.script",
"ambari.dispatch-property.script.filename" : "customdispatcher.py"
}
}
}
Create customdispatcher.py in /var/lib/ambari-server/resources/scripts/
## Writing notification to a file. Use your own logic here.
file = open("/var/log/ambari-server/custom_notification.log", "a+")
file.write("New notifiation")
file.close()
if __name__ == '__main__':
handle_alert()
Change file permissions.
chmod 777 /var/lib/ambari-server/resources/scripts/customdispatcher.py
chmod +x /var/lib/ambari-server/resources/scripts/customdispatcher.py
Add following line to ambari properties file
notification.dispatch.alert.script=/var/lib/ambari-server/resources/scripts/customdispatcher.py
Restart ambari
After these steps, I stop some services to trigger an alarm but get a warning in /var/log/ambari-server/ambari-server.log file and nothing is logged to custom_notification.log file.
2022-06-23 09:38:53,144 WARN [script-dispatcher-1] AlertScriptDispatcher$AlertScriptRunnable:363 - Unable to dispatch ALERT_SCRIPT notification because /var/lib/ambari-server/resources/scripts/customdispatcher.py terminated with exit code 2
Any ideas on how to fix this?

Telegram bot Message Handler error [Local varialbe referenced before assignment]

from dotenv import load_dotenv
import os
from panda import *
from telegram.ext import *
from telegram.update import *
load_dotenv('.env')
Token =os.getenv('TOKEN')
print("The bot connected .....")
# commands handler
# start message
def start_command(update,context):
update.message.reply_text("Hello am mr panda am here to help you: ")
# help command
def help_command(update,context):
res = panda.help()
update.message.reply_text(res)
# message handler
**def message_handle(update,context):
message = str(update.message.text).lower()
respose = panda.hello(message)
update.message.reply_text(respose)**
# errror handler
def error(update,context):
print(f"Update the context error : {context.error}")
# main function
def main():
global message
updater =Updater(Token,use_context=True)
dp = updater.dispatcher
# command handlers
dp.add_handler(CommandHandler("start",start_command))
dp.add_handler(CommandHandler("help",help_command))
**# message handlers
dp.add_handler(MessageHandler(Filters.text,message_handle))**
# error handlers
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
main()
This was the code Am getting error
Update the context error: local variable 'message' referenced before assignment
I think there is an error on the highlighted portions I do little searches and I referred to the documentation too I can't catch the error.
Does anyone have solution that would be great :)

unable to open database file on a hosting service pythonanywhere

I want to deploy my project on pythonanywhere. Error.log says that server or machine is unable to open my database. Everything works fine on my local machine. I watched a video of Pretty Printed from YouTube
This how I initialize in app.py. This what I got from error.log
db_session.global_init("db/data.sqlite")
this in db_session:
def global_init(db_file):
global __factory
if __factory:
return
if not db_file or not db_file.strip():
raise Exception("Необходимо указать файл базы данных.")
conn_str = f'sqlite:///{db_file.strip()}?check_same_thread=False'
print(f"Подключение к базе данных по адресу {conn_str}")
engine = sa.create_engine(conn_str, echo=False)
__factory = orm.sessionmaker(bind=engine)
from . import __all_models
SqlAlchemyBase.metadata.create_all(engine)
def create_session() -> Session:
global __factory
return __factory()
last thing is my wsgi.py:
import sys
path = '/home/r1chter/Chicken-beta'
if path not in sys.path:
sys.path.append(path)
import os
from dotenv import load_dotenv
project_folder = os.path.expanduser(path)
load_dotenv(os.path.join(project_folder, '.env'))
import app # noqa
application = app.app()
Usually errors like this on PythonAnywhere are due to providing relative path instead of absolute path.

why scrapy logs different in the console and external log file

I'm new to Scrapy and I once managed to run my script well on Scrapy 0.24. But when I switched to the newly launched 1.0 I encountered a logging problem: What I want to do is to set both the file and the console log level to INFO, but however I set the LOG_LEVEL or the configure_logging() function(using the Python internal logging package instead of scrapy.log), Scrapy always logs DEBUG level information to the console, which returns the whole item object in format of dict. In fact, the LOG_LEVEL option only works for the external file. I suspect it must have something to do with the Python logging but have no idea how to set it. Could any one help me out?
This is how I config my logging in run_my_spider.py:
from crawler.settings import LOG_FILE, LOG_FORMAT
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
from scrapy.utils.log import configure_logging
from crawler.spiders.MySpiders import MySpider
import logging
def run_spider(spider):
settings = get_project_settings()
# configure file logging
# It ONLY works for the file
configure_logging({'LOG_FORMAT': LOG_FORMAT,
'LOG_ENABLEED' : True,
'LOG_FILE' : LOG_FILE,
'LOG_LEVEL' : 'INFO',
'LOG_STDOUT' : True})
# instantiate spider
process = CrawlerProcess(settings)
process.crawl(MySpider)
logging.info('Running Crawler: ' + spider.name)
process.start() # the script will block here until the spider_closed signal was sent
logging.info('Crawler ' + spider.name + ' stopped.\n')
......
This is the console output:
DEBUG:scrapy.core.engine:Crawled (200) <GET http://mil.news.sina.com.cn/2014-10-09/0450804543.html>(referer: http://rss.sina.com.cn/rollnews/jczs/20141009.js)
{'item_name': 'item_sina_news_reply',
'news_id': u'jc:27-1-804530',
'reply_id': u'jc:27-1-804530:1',
'reply_lastcrawl': '1438605374.41',
'reply_table': 'news_reply_20141009'}
Many Thanks!
It may be that what you are viewing in the console is the Twisted Logs.
It will print the Debug level messages to the console.
You can redirect them to your log files using:
from twisted.python import log
observer = log.PythonLoggingObserver(loggerName='logname')
observer.start()
(As given in How to make Twisted use Python logging?)

ImproperlyConfigured: Requested setting MIDDLEWARE_CLASSES, but settings are not configured

i am confuring the apache mod_wsgi to django project
and here is my djangotest.wsgi file
import os
import sys
sys.path = ['/home/pavan/djangoproject'] + sys.path
os.environ['DJANGO_SETTINS_MODULE'] = 'djangoproject.settings'
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
return _application(environ, start_response)
and i add the WSGIScrptAlias to my virtual directory
when i try to get the homepage of the project it says the following error
ImproperlyConfigured: Requested setting MIDDLEWARE_CLASSES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Looks like you have a typo on line 4. 'DJANGO_SETTINS_MODULE' should be 'DJANGO_SETTINGS_MODULE'.