attempt to index a nil value (field 'eth0') - automation

this is a Lua quickapp problem i install it a year ago and it was working fine but went through some problems in my system because of electricity.
This is the part I Have problem with:
function BroadlinkDeviceManager:discover(func)
local blDevices = {}
local network = api.get("/proxy?url=http://localhost:11112/api/settings/network")
local myIP = network.networkConfig.eth0.ipConfig.ip
-- for debugging
if dofile then
myIP = "192.168.1.59" -- Util.getIPaddress() --
end
The Quick app is for Broadlink RM4 when I setup it again to my wifi the QA always give me this error
[DEBUG] [QUICKAPP1613]: ./include/manager.lua:97: attempt to index a nil value (field 'eth0')
[ERROR] [QUICKAPP1613]: QuickApp crashed
[ERROR] [QUICKAPP1613]: Unknown error occurred: handleJsonRpc
I search it but i can't find any solution I also asked in forum but I got nothing.
If there is any one can help me with this.

You must verify if network.networkConfig.eth0 is not nil before indexing network.networkConfig.eth0.ipConfig.ip :
local myIP
if network.networkConfig.eth0 ~= nil then
myIP = network.networkConfig.eth0.ipConfig.ip
end

Thank you for your response, the error disappear put there was a function to check the IP of the device
local function makeDiscoverDevicesMsg()
local ipa1, ipa2,ipa3, ipa4 = myIP:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)")
then I edit to be "^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$"
I also try to make every variable with (tonumber) but all give me the same error attempt to index a nil value (upvalue 'myIP')

Related

How do I handle session id context uninitialized in Thrift

sorry to bother you guys,
I have a Thrift server program in c++. Whenever a client connects to me, the handshake succeeds, as does the first Thrift command sent, but the second command sent fails with the error "session id context uninitialized".
The client's next command re-establishes the connection and succeeds, but the fourth will fail again with "session id context uninitialized".
The exact error is
TConnectedClient died: SSL_accept: session id context uninitialized (SSL_error_code = 1)
TConnectedClient input close failed: session id context uninitialized (SSL_error_code = 1)
TConnectedClient output close failed: session id context uninitialized (SSL_error_code = 1)
every 'even' command
My problem seems similar to THIS, but I can't seem to figure out how to change the context of my session to set the SSL_OP_NO_TICKET flag.
I tried adding a ServerEventHandler, but I don't think I can change the serverContext that is present there.
Can anyone help me?
Below is the section of main() where I declare and start the server. If more information is needed, please ask. (sorry if I typo-ed any code, I had to retype by hand it here)
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactoryT<TBufferBase>());
::apache::thrift::stdcxx::shared_ptr<My_svrHandler> handler(new My_svrHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new My_svrProcessor(handler));
::apache::thrft::stdcxx::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory(SSL::TLSv1_2));
sslSocketFactory->loadCertificate(certLocation);
sslSocketFactory->loadPrivateKey(keyLocation);
sslSocketFactory->loadTrustedCertificates(CALocation);
sslSocketFactory->authenticate(true);
::apache::thrift::stdcxx::shared_ptr<TServerSocket> serverSocket(new TSSLServerSocket(9090, sslSocketFactory));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<apache::thrift::server::Tserver> server;
::apache::thrift::stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(10);
::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory> threadFactory = ::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
server.reset(new TThreadedPoolServer(processor, serverSocket, transportFactory, protocolFactory, threadmanager));
if(server.get() != NULL)
{
apache::thrift::concurrency::PlatformThreadFactory factory;
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Thread> thread = factory.newThread(serverThreadRunner);
signal(SIGPIPE, SIG_IGN);
thread->start();
while(1){}
server->stop();
thread->join();
server.reset();
}

Is there a solution to the problem es_extended Fivem

problem = SCRIPT ERROR: es_extended:modules/core/player/server/events.lua:150: attempt to index a nil value (field 'UsableItemsCallbacks')
task (es_extended:modules/core/player/server/events.lua:150)
processQueue (#async/async.lua:67)
parallelLimit (#async/async.lua:86)
ref (es_extended:modules/core/player/server/module.lua:180)
(#mysql-async/mysql-async.js:15543)
This error is because of some wrong configuration(happened with me a while ago before I stopped using ESX). Recheck your config files and if that still doesn't work try disabling the ESX default loadscreen. Lastly, set up clean ESX again and see if that works.

How can I check if my "variable" is a valid "ID"

API: https://github.com/satom99/litcord
How can I check my valiable if its a valid ID?
local cmd, serverID, channelID, arg = string.match(message.content, '(%S+) (%d+) (%d+) (%S+.*)')
local server = client.servers:get('id', serverID)
serverID is the variable and I need to check if the serverID is a valid ID
Otherwise I will get an error that server is a nil value.
I am trying days to finish one command and this is a part of it.
If you need more contents then please tell me, I will link it to you.
Full Code:
client:on(
'message',
function(message)
local userID = message.author.id
local cmd, serverID, channelID, arg = string.match(message.content, '(%S+) (%d+) (%d+) (%S+.*)')
local server = client.servers:get('id', serverID)
local channel = server.channels:get('id', channelID)
local cmd = cmd or message.content
if (cmd == "!say") and message.parent.is_private then
if (userID == "187590758360940545") then
if not server then
return
end
if (server == servers) then
if (channel == channels) then
message.channel:sendMessage(arg)
else
message:reply("I don't know this channel.")
return
end
message:reply("I don't know this server.")
end
else
message:reply(":sob: Stop!!!!")
end
end
end
)
And how I can let it write in the channel I want with functions
message.channel:sendMessage(arg)
this is like message:reply
it replies back where the message came from.
Let's forget about validating the serverID for one moment.
Of course you should always handle the case client.servers:get('id', serverID) returing nil.
Simply validating serverID somehow and hoping that you will get a valid server handle back is not an option.
So either use Luas error handling features https://www.lua.org/manual/5.3/manual.html#2.3
or simply check server with an if statement so you won't use server if it is nil.
Simplified:
local server = client.servers:get('id', serverID)
if not server then
print("No server with id '" .. serverID .. "' found.")
return -- or do something clever here, show a message box or whatever...
end
-- server won't be nil from here
Unless you know for sure that there is no other way for nil being returned you should handle that possibility properly.

mod_perl error returning 202 Apache2::Const::HTTP_ACCEPTED

I am trying to build a simple asynchronous web service with Apache and mod_perl. But every time I try to return HTTP status 202 (Accepted), I get an error.
Below a very simple example (non-asynchronous):
package MyHandler;
use Apache2::Const '-compile' => qw 'OK HTTP_ACCEPTED HTTP_OK';
use Apache2::RequestRec;
use CGI;
sub handler {
my $r = shift;
print "Hallo";
$r->content_type('text/plain');
$r->status(Apache2::Const::HTTP_ACCEPTED);
return Apache2::Const::HTTP_ACCEPTED;
}
1;
I get the error
calling the handler in my browser on localhost, I get the output but also an error:
Hallo
Accepted
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
I also get an error with Apache2::Const::HTTP_OK, the only one that works without error is Apache2::Const::OK.
My apache error log makes no mention of this error.
With mod_perl2 you do not return HTTP status codes (this is why it is necessary to use $r->status() so set the HTTP status code.
Instead, you return a value depending on what you want the server to do. The most common would be Apache2::Const::OK. This tells the server your handler has finished successfully. This constant, if I recall correctly, has an integer value of 0, not 200.
Returning an HTTP status code from a mod_perl handler will be interpreted as an error.
https://perl.apache.org/docs/2.0/user/handlers/intro.html#Handler_Return_Values
Different handler groups are supposed to return different values.
Make sure that you always explicitly return a wanted value and don't rely on the result of last expression to be used as the return value -- things will change in the future and you won't know why things aren't working anymore.
The only value that can be returned by all handlers is Apache2::Const::OK, which tells Apache that the handler has successfully finished its execution.
Apache2::Const::DECLINED is another return value that indicates success, but it's only relevant for phases of type RUN_FIRST.
HTTP handlers may also return Apache2::Const::DONE which tells Apache to stop the normal HTTP request cycle and fast forward to the PerlLogHandler, followed by PerlCleanupHandler. HTTP handlers may return any HTTP status, which similarly to Apache2::Const::DONE will cause an abort of the request cycle, by also will be interpreted as an error. Therefore you don't want to return Apache2::Const::HTTP_OK from your HTTP response handler, but Apache2::Const::OK and Apache will send the 200 OK status by itself.
Try NOT printing anything BEFORE you set your content-type header.

HTTPSConnectionPool Max retries exceeded

I've got a django app in production running on nginx/uwsgi. We recently started using SSL for all our connections. Since moving to SSL, I often get the following message:
HTTPSConnectionPool(host='foobar.com', port=443):
Max retries exceeded with url: /foo/bar
Essentially what happens is I've got the browser communicating with django server code, which then uses the requests library to call an api. Its the connection to the api that generates the error. Also, I've moved all our requests into one session (a requests session, that is), but this hasn't helped.
I've bumped up the number of uwsgi listeners since I thought that could be the problem, but our load isn't that high. Also, we never had this problem before SSL. Does anyone have some advice as to how to solve this problem?
Edit
Code snippet of how I call the API. I've posted it (mostly) verbatim. Note its not the code that actually fails, but the requests library that throws an exception when calling self.session.post
def save_answer(self):
logger.info("Saving answer to question")
url = "%s1.0/exam/learneranswer/" % self.api_url
response = {'success': False}
data = {'questionorder': self.request.POST.get('questionorder'),
'paper': self.request.POST.get('paper')}
data['answer'] = ",".join(self.request.POST.getlist('answer'))
r = self.session.post(url, data=simplejson.dumps(data))
if r.status_code == 201:
logger.info("Answer saved successfully")
response['success'] = True
elif r.status_code == 400:
if r.text == "Paper expired":
logger.warning("Timer has expired")
response['message'] = 'Your time has run out'
if r.text == "Question locked":
response['message'] = \
'This question is locked and cannot be answered anymore'
else:
logger.error("Unknown error")
self.log_error(r, "Unknown Error while saving answer")
else:
logger.error("Internal error")
self.log_error(r, "Internal error in api while saving answer")
return simplejson.dumps(response)
I've found that this error happens when some item in one of my views throws an exception. For example, when using the django 'requests' framework to post data to another URL:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5)
The downrange server was having connection issues, which threw an exception and that bubbled up and gave me the error you had above. I replaced with this:
try:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5)
except requests.exceptions.ConnectionError as e:
r = "No response"
And that fixed it (of course, I'd suggest adding in more error handling, but the above is the relevant subset).
You must disable validation like this
requests.get('https://google.com', verify=False)
You should specify your CA.
This Error occurs as a result of python script trying to connect to IBM service even before your wifi or ethernet connection is established. Have a try/catch to rectify or if trying to run as service then run service after network is established.