Python System Call Cannot Find File, Error Running on Apache Server - android

I'm trying to run an os.system() call from my Python class to source a file I have stored in the file. I am connecting to a server from an Android application and running a method in Django to run a system call. The server is running Apache with mod_wsgi to deploy Django. This is the Django method:
def post_try(request):
os.chdir("/usr/local/src")
response = os.system("source sourceme")
return HttpResponse(response)
The code works fine as far as syntax goes, all necessary imports are done, however I keep getting a 256 error code back instead of the expected 0. I check the error in the Apache log and this is what I get:
[Sun Aug 18 19:43:23 2013] [notice] caught SIGTERM, shutting down
[Sun Aug 18 19:43:24 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sun Aug 18 19:43:24 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sun Aug 18 19:43:24 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sun Aug 18 19:46:04 2013] [notice] caught SIGTERM, shutting down
[Sun Aug 18 19:46:05 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sun Aug 18 19:46:05 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sun Aug 18 19:46:05 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
sh: line 0: source: sourceme: file not found
I cannot figure out what is going on. I have the sourceme file clearly in the /usr/locals/src/ folder, which I have verified many times using ls. I do not know what is happening. I used os.getcwd() to check that the directory is being changed correctly, but the file still cannot be found. Please let me know if there is anything that I am missing, as I am very frustrated at this problem that I can just not realize.
Thank you

Your approach currently does not make sense:
os.system creates a child process of the WSGI process, while the environment of the parent is passed on to the child, the environment of the child is not passed back/shared with the parent.
Also, source is not a binary, but a built-in function of the shell itself.
If you want to set environment variables us os.environ which is a dictionary of the variables.
Since you are using python, it would be much more sensible to use python program instead of some os.system calls. That is, create python program with the environment variables, add it to your PYTHONPATH and import it in your django code.

Related

Samsung SM A550W HTTPS ExtCertPathValidatorException with wrong date

My app runs on all devices and simulators Except Samsung SM-A500W. It just failed to update the database. The access to the database is through php scripts stored in a TLD secure domain (Access only through httpS).
The failure is because it thinks the expiration date of the certificate is passed....not true. See LogCat.
10-25 11:07:18.381 25547-25617/uro2.tradersmicro.com.uro2 D/Uploadi16: Exception jb: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: Certificate expired at Sat Feb 18 18:59:59 EST 2017 (compared to Thu Oct 25 11:07:18 EDT 2018) javax.net.ssl.SSLHandshakeException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: Certificate expired at Sat Feb 18 18:59:59 EST 2017 (compared to Thu Oct 25 11:07:18 EDT 2018)
BTW. One of the fragments of my app uses a WebView. The secure database access in this part is normal.
Is there a way to avoid this error?
The way I found to circumvent this problem is to copy the php scripts to a Non Secure Domain, and ensure that they get updated as the scripts are updated.
At run time:- in the try...catch of the database access to change the domain to the insecure one. So far works like a charm.
Of course the database access occurs in an Async task, it seems ok to call the method again, recursively from the catch code.
I would suggest trying to update the device security provider using the Google Play Service:
https://developer.android.com/training/articles/security-gms-provider
import com.google.android.gms.security.ProviderInstaller;
// ....
try {
ProviderInstaller.installIfNeeded(getContext());
} catch (GooglePlayServicesRepairableException e) {
// TODO handle error
}

Unable to compile Android app - Error 256 in Corona

I am using Corona SDK and I am trying to compile my app for Android. I have been able to compile for iOS.
When compiling using either a fully signed distribution key or a debug key I am given the following error:
Build Failed: Error code: 256
The full error is as follows:
Sep 23 01:24:00.635 Building Android app for mgr****#**.com with 2017.3135
Sep 23 01:24:02.541 BUILD SUCCESSFUL
Total time: 0 seconds
Sep 23 01:24:02.542
Sep 23 01:25:24.905 BuildID: 59c5a9a30bb42
Sep 23 01:25:34.119 [exec] Result: 1
Sep 23 01:25:36.428 BUILD FAILED
/Applications/Corona/Corona Simulator.app/Contents/Resources/build.xml:479: The following error occurred while executing this line:
/Applications/Corona/Corona Simulator.app/Contents/Resources/build.xml:454: jarsigner returned: 1
Total time: 6 seconds
Sep 23 01:25:36.539 Android build failed (256) after 95 seconds
Sep 23 01:25:36.816 ERROR: Build Failed: Error code: 256
I have tried Google Play and Amazon targets with the same outcome.
Any ideas massively appreciated.
I was able to compile the exact same files on a different machine (Windows) without an issue. I guess this is down to the Java installation on the other machine.
Interestingly, Corona required the 32-bit version of Java on Windows, which meant downloading a slightly older SDK/JDK (latest SDK only has 64-bit builds). My Mac has the latest 64-bit build, which Corona does not complain about, but isn't able to build with.

CouchDB Replication / Timeout Error

I'm running CouchDB with Yocto Dizzy on a LogicPD Torpedo with a 1GHz processor. I have multiple Android devices connected, making changes, and syncing with this database through some Java and Nodejs code. For the most part, it looks like the database is replicating properly across all devices.
However, I do have a frequent issue where a device will fall out of sync and the Android app on that device will have to be restarted. By "fall out of sync" I mean that changes are being made on one device, synced to the database, and not showing up on another device. I'm trying to troubleshoot this problem and I haven't been able to find any errors on the Android side. The errors I'm seeing in the CouchDB log are:
[Fri, 25 Sep 2015 14:47:59 GMT] [error] [<0.222.0>] ** Generic server <0.222.0> terminating
** Last message in was {'EXIT',<0.217.0>,killed}
** When Server state == {state,"http://X.XXX.X.X:XXXX/task/",20,[],
[<0.338.0>],
{[],[]}}
** Reason for termination ==
** killed
[Fri, 25 Sep 2015 14:47:59 GMT] [error] [<0.222.0>] {error_report,<0.31.0>,
{<0.222.0>,crash_report,
[[{initial_call,
{couch_replicator_httpc_pool,init,['Argument__1']}},
{pid,<0.222.0>},
{registered_name,[]},
{error_info,
{exit,killed,
[{gen_server,terminate,7,
[{file,"gen_server.erl"},{line,804}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]}},
{ancestors,
[<0.217.0>,couch_replicator_job_sup,
couch_primary_services,couch_server_sup,<0.32.0>]},
{messages,[]},
{links,[<0.338.0>]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,610},
{stack_size,27},
{reductions,390}],
[]]}}
[Fri, 25 Sep 2015 14:48:06 GMT] [error] [<0.130.0>] Error in replication `b16486bad369b219600dbd5bf0478e81+continuous+create_target` (triggered by document `9be140c9aa6334820aed80fa910275e4`): timeout
Restarting replication in 5 seconds.
[Fri, 25 Sep 2015 14:48:06 GMT] [error] [<0.88.0>] {error_report,<0.31.0>,
{<0.88.0>,supervisor_report,
[{supervisor,{local,couch_replicator_job_sup}},
{errorContext,shutdown_error},
{reason,killed},
{offender,
[{pid,<0.157.0>},
{name,
"98e4832e6f31a0962493d26092b5fe4e+continuous+create_target"},
{mfargs,{gen_server,start_link,undefined}},
{restart_type,temporary},
{shutdown,250},
{child_type,worker}]}]}}
When running the same programs and database on CentOS with an i7, it all works perfectly. I've tried mucking with tcp/ip kernel settings, as well as CouchDBs settings (local.ini, specifically os_process and timeout options).
Does anyone have any experience in this area? Any help would be greatly appreciated!

getting "androidApplicationContext must be not null!" crashes from crash reporting service

after supporing linkedin social network, an app i'm working on has caused many crashes that the only thing that is written there is "androidApplicationContext must be not null!" .
i've searched the internet , and found only the next links as clues:
http://pastebin.com/QeV9D8XH
http://logs.nslu2-linux.org/livelogs/android-dev/android-dev.20120829.txt
it says :
Aug 28 17:15:23 <S3nsat10n> has anyone run across a stacktrace like this? http://pastebin.com/QeV9D8XH
Aug 28 17:15:33 <S3nsat10n> has to do with a null app context inside the apache httpclient
Aug 28 17:15:38 <Hodapp> wongk: yeah, I'm just really confused about why it's doing this...
Aug 28 17:15:47 <S3nsat10n> highly modified httpclient it would seem, judging my the naf.gba package stuff
Aug 28 17:15:51 <S3nsat10n> Seems to be happening only on Samsung Galaxy S devices, but I don't know if that's always the case.
Aug 28 17:16:48 <wongk> S3nsat10n: never see that
Aug 28 17:16:50 <wongk> seen
Aug 28 17:17:17 <S3nsat10n> yeah :/
Aug 28 17:17:22 <S3nsat10n> neither has most of the internet...
Aug 28 17:17:23 <S3nsat10n> heh
has anyone else got this weird and super rare error?
if so how did you fix it?
Two solutions :
Use HttpURLConnection instead of HttpClient
Create an instance of HttpClient in the main thread of your application, as soon as possible, for instance in its onCreate method.
More details here.

GCM server using app engine for java not working

So i have followed the GCM Demo application tutorial. http://developer.android.com/guide/google/gcm/demo.html
I got it working with jetty server.
But now i would like to do the app engine for java server and it is not working.
I am sure that my client is configured oke, because it was working for jetty server.
In ApiKeyInitializer.java i replaced "replace_this_text_by_your_Simple_API_Access_key" with my access key.
I copied the appengine sdk to a simple location D:\appenginesdk
Than i run in cmd:
ant -Dsdk.dir=D:\appenginesdk runserver -Dserver.host=192.168.0.101
Where 192.168.0.101 is my local ip.
D:\gmcserverapp>ant -Dsdk.dir=D:\appenginesdk runserver -Dserver.host=192.168.0.101
Buildfile: D:\gmcserverapp\build.xml
init:
copyjars:
compile:
[javac] Compiling 1 source file to D:\gmcserverapp\WebContent\WEB-INF\classes
[javac]
[javac] WARNING
[javac]
[javac] The -source switch defaults to 1.7 in JDK 1.7.
[javac] If you specify -target 1.5 you now must also specify -source 1.5.
[javac] Ant will implicitly add -source 1.5 for you. Please change your build file.
[javac] warning: [options] bootstrap class path not set in conjunction with-source 1.5
[javac] 1 warning
datanucleusenhance:
[enhance] DataNucleus Enhancer (version 1.1.4) : Enhancement of classes
[enhance] DataNucleus Enhancer completed with success for 0 classes. Timings :input=156 ms, enhance=0 ms, total=156 ms. Consult the log for full details
[enhance] DataNucleus Enhancer completed and no classes were enhanced. Consult the log for full details
runserver:
[java] aug 21, 2012 1:17:55 PM com.google.apphosting.utils.jetty.JettyLogger info
[java] INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
[java] aug 21, 2012 1:17:55 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
[java] INFO: Successfully processed D:\gmcserverapp\WebContent\WEB-INF/appengine-web.xml
[java] aug 21, 2012 1:17:55 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
[java] INFO: Successfully processed D:\gmcserverapp\WebContent\WEB-INF/web.xml
[java] aug 21, 2012 3:17:57 PM com.google.appengine.tools.development.DevAppServerImpl start
[java] INFO: The server is running at http://192.168.0.101:8080/
[java] aug 21, 2012 3:17:57 PM com.google.appengine.tools.development.DevAppServerImpl start
[java] INFO: The admin console is running at http://192.168.0.101:8080/_ah/admin
This is what i get in the emulator
And in the browser i get no device registered.
What can i do?
What am i doing wrong?
I did a lot of tutorials, nothing worked, i am becoming desperate.
EDIT 2012-08-21 15:57:
Thanks Yahor10, that solved some errors.
I now get this error:
[java] aug 21, 2012 1:52:40 PM com.google.appengine.tools.development.LocalResourceFileServlet doGet
[java] WARNING: No file found for: //register
EDIT 2012-08-21 16:18:
// String serverUrl = SERVER_URL + "/register";
String serverUrl = SERVER_URL;
I changed the server_url in serverUtilities.java for the android app. This made the emulator say that it is connected. But when i refresh 192.168.0.101:8080 it still gives No devices.....
I had been having similar difficulties with the GCM demo until I figured out that the server_url I had was incorrect. I had set it to 'http://< my_ip_address>:8080/gcm-demo' as the example and tutorial suggest. And whats more, ant was giving me a log for everytime the app tried to contact the server, so I didn't think the url was incorrect.
But I just took out the '/gcm-demo' from the end of the url and it works like a charm.
Hope this was/is what was giving you a headache.
-Mrdresden
Set 1.7 java code in your server build.xml
<target name="compile" depends="init" description="Compile the Java classes.">
<javac destdir="${classes}" debug="true" srcdir="${src}" target="1.7"
includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>
Set correct dir location of App engine sdk and
write correct ip address of your computer on the client side

Categories

Resources