I am trying to automate android mobile using python's pure-python-adb package but when I run the following code:
from ppadb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
print(client.version())
I get error in Pycharm as:
RuntimeError: ERROR: connecting to 127.0.0.1:5037 [WinError 10061] No connection could be made because the target machine actively refused it.
Is adb running on your computer?
Please can anyone help me with it
Switch on developer mode in your phone and connect it to your laptop using a physical data transfer (or changing) cable.
REMEMBER: Switch on 'USB debugging' on your phone.
Then go to cmd terminal and make sure you have adb requirements from android studio installed. Once that's there, go to terminal and type.
adb devices
if your phone shows up, you should be connected. You can then type
adb shell
or:
adb connect tcpip 5555
to connect over the internet
Related
I am able to connect an Android device with ADB using a USB cable but I want to connect a remote device without a USB cable, and not rooted also. I am running the ADB command through Python. I have been googling for 2 days and most of the resources say we can't do this. If it's not possible, please suggest other options.
Is this possible with a Python script?
I am trying to simulate tap and swipe gesture from adb to my android device. I've tried to run the following command
adb shell input tap 500 500 and adb shell input touchscreen tap 500 500 from windows command prompt. It is giving me the following error,
java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.createException(Parcel.java:2074)
at android.os.Parcel.readException(Parcel.java:2042)
at android.os.Parcel.readException(Parcel.java:1990)
at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:925)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:886)
at com.android.commands.input.Input.injectMotionEvent(Input.java:428)
at com.android.commands.input.Input.access$200(Input.java:41)
at com.android.commands.input.Input$InputTap.sendTap(Input.java:224)
at com.android.commands.input.Input$InputTap.run(Input.java:218)
at com.android.commands.input.Input.onRun(Input.java:108)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:56)
at com.android.commands.input.Input.main(Input.java:71)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:380)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.input.InputManagerService.injectInputEventInternal(InputManagerService.java:732)
at com.android.server.input.InputManagerService.injectInputEvent(InputManagerService.java:706)
at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:422)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
I've also tried to execute the same command from python script with the pure-python-adb package. The following is script I've exucted.
from ppadb.client import Client
adb = Client()
devices = adb.devices()
if len(devices) == 0:
print("No devices attached")
quit()
device = devices[0]
print(device)
device.shell('input touchscreen tap 700 1453')
I got the following output with no tap noticed on device and no error from the script.
<ppadb.device.Device object at 0x02B30E50>
Am I missing anything (Might be in developer's option setting for android)?
I am on windows 10 machine with adb version 1.0.41. And using an android device with Android 10 (Android Q) over a usb.
Look for a "USB debugging (Security Settings)" or something similar in your developer options in the debugging section -- This is where you grant ADB special permissions and allow input.
Best of luck; I hope you find it.
I tried this to tap a xy coordinate using adb command. Enabling the "USB debugging (Security Settings)" is worked for me. But the phone should connect to the internet inorder to enable the settings.
Thanks #Meer
I've set a .py file to run at startup of my Raspberry according to this guide : https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
Method 4: Systemd
I did exactly as the tutorial, and the file does play at startup as expected. However, since that moment i've been unable to access the Raspberry via SSH or VNC, I ping to the Raspberry Address and I got positive response, but when I try to connect via SSH I get
"ssh: connect to host 192.168.1.250 port 22: Connection refused"
Since i'm working headless i'm unable to check what's wrong.
Any advice? thanks in advance!
Take the SD card out of the Raspberry Pi and put it in another computer. Create a file called ssh in the boot filesystem. Use touch ssh to create the file.
Put SD card back in Raspberry Pi and reboot. You will be able to ssh into it, then use sudo raspi-config to enable ssh permanently.
Here is what I am trying to do. I have a Windows VM and another Linux VM which is used as server. I have Spyder installed on my Windows VM and would like to run my Python code in Spyder on remote Linux server.
I did try using option in Spyder called "Connect to remote kernel" but it did not work and I am getting error "Could not open ssh tunnel ; Paramiko not available". I was using username#servername:22 for making ssh connection. Needless to say, I am able to ssh the machine using putty but not using Spyder. Any ideas how should I fix this?
I found another way to make a connection to an external server, here is the link explaining step by step.
Basically, you have to connect your client PC to the server through a PuTTY SSH tunnel, it will allow to redirect the client ports to the correct ipython kernel server ports.
Lately I've been playing with Python to discover its potential and I've just stumbled upon SimpleHTTPServer.
I'm on Windows 10.
I run:
python -m SimpleHTTPServer
the output is:
Serving HTTP on 0.0.0.0 port 8000 ...
I've opened the browser both on smartphone and tablet, but none of them can connect to the server when I type "http://127.0.0.1:8000".
(Translating from italian, maybe is not the exact translation)
iPad: "Safari can't open the page because the server has stopped responding"
Android: "WebPage does not respond. the webpage may be temporarily not available or it could have been moved to another address"
Why does it not work? How do I fix this?
Maybe your firewall is blocking access to python based server
Try this:
Open windows firewall
click on "allow an app or feature..." on the left side of the opened window
search for python in the list and check both the boxes private and public
It should work now
127.0.0.1 is always the IP address of the local system (its associated hostname is "localhost"). In other words, if you type 127.0.0.1:8000 on your tablet or Android device, the browser on that device will try to connect to a server running on the same device, listening on port 8000. You'll need to find out the IP address of the computer you're running Python on, and type that instead. You can use the ifconfig command on Unix, or ipconfig on Windows.