0

I have HTC One X, with Android 4. I have install sl4a, python, scapy and terminal IDE on my smartphone. All is alright, python in terminal IDE work well with scapy as root.

The problem happens when i use SL4A.

droid=android.Android(('127.0.0.1', '58322'))
droid.makeToast('Hello, Android!')

When i run the script there is no error, but at interpretation of makeToast() the program stops and nothing happens.

Anyone can help me to run a python script as root with SL4A in Terminal ?

  • Have you tried other commands instead of `makeToast`? I think the problem is at the first line when it tries to make a connection to that address. Maybe your IDE doesn't print errors, i don't know for sure. – Radu Gheorghiu Jul 09 '12 at 09:53

2 Answers2

0

I can tell you how to run it as root, but first let me mention that I do not believe that this is your issue. To make sure, try running this script:

# author: Matthew Downey
# purpose: Hello World.py script for android with SL4A

import android #this makes sure you can run android functions

droid = android.Android()

droid.makeToast('Hello, Android!') #uses the android module to display a user message


This should run fine, and does not require root. However if you are running a python script on your android that does require root (say you are using subprocess.call(command) to execute a command that requires root), try this (from the terminal on your android):

app_148@cdma_spyder:/ $ cd filepath_to_mypythonprogram/myProgram.py
app_148@cdma_spyder:/ $ su
app_148@cdma_spyder:/ # python myProgram.py


This should effectively run the python script as root, assuming your phone is rooted!

John Dorian
  • 1,884
  • 1
  • 19
  • 29
0

This might be of help: https://groups.google.com/forum/?fromgroups=#!searchin/python-for-android/socket.gaierror/python-for-android/s1rX9fTYPQQ/6_pHEm13gQwJ

Also your port shouldn't be in single quotes.

Andrew Stern
  • 688
  • 9
  • 18