Could not find 'adb.exe' in ......? - python-3.x

How to fix Could not find 'adb.exe'?
I think my question is one of the most asked and answered question of the Android world. I read and tried them all.
I checked and update my environment variables.
I desinstalled and reinstalled ANdroid Studio
I copied pasted adb in all possible folders:
C:\Users\Nino\AppData\Local\Android\Sdk
C:\Program Files\Android
C:\Program Files\Android\tools
C:\Program Files\Android\platform-tools
In fact I spent all the day by searching, reading and testing all the solution possible.
And nothing fixed my problem. So I really need your help.
I am newbie and I want to share my experience. Here is my code:
from appium import webdriver
import unittest
from selenium.webdriver.common.by import By
class Instagram(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName']='Android'
desired_caps['platformVersion']='6.0'
desired_caps['deviceName']='S6S5IN3G'
desired_caps['noReset']='true'
desired_caps['appPackage']='com.instagram'
desired_caps['appActivity']='com.instagram.android.activity.MainTabActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
#self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub',desired_caps)
def tearDown(self):
self.driver.quit()
def test_scrap_email(self):
search_button = self.driver.findElement(By.xpath ("//android.widget.ImageView[#bounds='[126,800][162,836]']"))
search_button.click()
if __name__ == '__main__':
suite = unittest.Testloader().loadTestsFromTestCase(Instagram)
unittest.TextTestRunner(verbosity=1).run(suite)
This is the errors:
Testing started at 01:00 ...
C:\Users\Nino\PycharmProjects\Instagram\venv\Scripts\python.exe
"C:\Program Files\JetBrains\PyCharm Community Edition
2019.1.3\helpers\pycharm_jb_unittest_runner.py" --target mybot_instagram.Instagram.test_scrap_email Launching unittests with
arguments python -m unittest
mybot_instagram.Instagram.test_scrap_email in
C:\Users\Nino\PycharmProjects\Instagram
Error Traceback (most recent call last): File
"C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\unittest\case.py",
line 59, in testPartExecutor
yield File "C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\unittest\case.py",
line 624, in run
self.setUp() File "C:\Users\Nino\PycharmProjects\Instagram\mybot_instagram.py", line 17,
in setUp
self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps) File
"C:\Users\Nino\PycharmProjects\Instagram\venv\lib\site-packages\appium\webdriver\webdriver.py",
line 144, in init
proxy File "C:\Users\Nino\PycharmProjects\Instagram\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 157, in init
self.start_session(capabilities, browser_profile) File "C:\Users\Nino\PycharmProjects\Instagram\venv\lib\site-packages\appium\webdriver\webdriver.py",
line 219, in start_session
response = self.execute(RemoteCommand.NEW_SESSION, parameters) File
"C:\Users\Nino\PycharmProjects\Instagram\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response) File "C:\Users\Nino\PycharmProjects\Instagram\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: An unknown
server-side error occurred while processing the command. Original
error: Could not find 'adb.exe' in ["C:\Program
Files\Android\platform-tools\platform-tools\adb.exe","C:\Program
Files\Android\platform-tools\emulator\adb.exe","C:\Program
Files\Android\platform-tools\tools\adb.exe","C:\Program
Files\Android\platform-tools\tools\bin\adb.exe"]. Do you have
Android Build Tools installed at 'C:\Program
Files\Android\platform-tools'?
Assertion failed
C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\unittest\case.py:656:
ResourceWarning: unclosed
outcome.errors.clear() ResourceWarning: Enable tracemalloc to get the
object allocation traceback
Ran 1 test in 2.139s
FAILED (errors=1)
Process finished with exit code 1
Assertion failed
Assertion failed
I am using pycharm. When I run the code I see some error log, but when I run it from cmd, there is nothing.
And here the main part of Appium log:
> Android >= 6, since UIAutomator1 framework is not maintained anymore by the OS vendor.
> [Appium] Appium v1.13.0 creating new AndroidDriver (v4.15.1) session
> [Appium] Capabilities:
> [Appium] platformName: Android
> [Appium] platformVersion: 6.0
> [Appium] deviceName: S6S5IN3G
> [Appium] noReset: true
> [Appium] appPackage: com.instagram
> [Appium] appActivity: com.instagram.android.activity.MainTabActivity
> [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"platformName":"Android","... were
> provided
> [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
> [BaseDriver] Capability 'noReset' changed from string to boolean. This may cause unexpected behavior
> [BaseDriver] Session created with session id: 786ec1a0-280c-4573-a917-18df120f0629
> [AndroidDriver] Shutting down Android driver
> [AndroidDriver] Called deleteSession but bootstrap wasn't active
> [BaseDriver] Event 'newSessionStarted' logged at 1566428435932 (01:00:35 GMT+0200 (Paris, Madrid (heure d’été)))
> [W3C] Encountered internal error running command: Error: Could not find 'adb.exe' in ["C:\\Program
> Files\\Android\\platform-tools\\platform-tools\\adb.exe","C:\\Program
> Files\\Android\\platform-tools\\emulator\\adb.exe","C:\\Program
> Files\\Android\\platform-tools\\tools\\adb.exe","C:\\Program
> Files\\Android\\platform-tools\\tools\\bin\\adb.exe"]. Do you have
> Android Build Tools installed at 'C:\Program
> Files\Android\platform-tools'?
> [W3C] at ADB. (C:\Users\Nino\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:106:11)
> [W3C] at Generator.next ()
> [W3C] at asyncGeneratorStep (C:\Users\Nino\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\#babel\runtime\helpers\asyncToGenerator.js:3:24)
> [W3C] at _next (C:\Users\Nino\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\#babel\runtime\helpers\asyncToGenerator.js:25:9)
> [W3C] at run (C:\Users\Nino\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\core-js\modules\es6.promise.js:75:22)
> [W3C] at C:\Users\Nino\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\core-js\modules\es6.promise.js:92:30
> [W3C] at flush (C:\Users\Nino\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\core-js\modules\_microtask.js:18:9)
> [W3C] at process._tickCallback (internal/process/next_tick.js:61:11)
> [HTTP] <-- POST /wd/hub/session 500 49 ms - 1544
> [HTTP]
Can anyone suggest me some solutions please?
THank you.

You need to have adb.exe in your operating system PATH
I would recommend going for the following setup:
Create ANDROID_HOME environment variable pointing to your Android SDK installation
Create JAVA_HOME environment variable pointing to your JDK installation
Create PATH environment variable like:
%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
That should be sufficient to successfully launch your Python Appium test
You can always use appium-doctor tool in order to check the integrity of your Appium pre-requisites installation.
More information:
Appium Getting Started
Appium - Code Examples - Python

Related

AnkiConnect Error Message in Anki When Attempting to Add New Flashcards from MPV Video Player

I have installed AnkiConnect, but it doesn't seem to work when attempting to add new flashcards with mpvacious, VocabSieve, or other tools. AnkiConnect v.6 shows it is working at http://localhost:8765/. I am using macOS.
I get the error message below in Anki:
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.49 (dc80804a) Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
Platform: Mac 10.16
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-04-30 14:46:27
Add-ons possibly involved: ⁨AnkiConnect⁩
Caught exception:
Traceback (most recent call last):
File "/Users/matt/Library/Application Support/Anki2/addons21/2055492159/__init__.py", line 96, in advance
self.server.advance()
File "/Users/matt/Library/Application Support/Anki2/addons21/2055492159/web.py", line 135, in advance
self.advanceClients()
File "/Users/matt/Library/Application Support/Anki2/addons21/2055492159/web.py", line 150, in advanceClients
self.clients = list(filter(lambda c: c.advance(), self.clients))
File "/Users/matt/Library/Application Support/Anki2/addons21/2055492159/web.py", line 150, in <lambda>
self.clients = list(filter(lambda c: c.advance(), self.clients))
File "/Users/matt/Library/Application Support/Anki2/addons21/2055492159/web.py", line 67, in advance
self.writeBuff += self.handler(req)
File "/Users/matt/Library/Application Support/Anki2/addons21/2055492159/web.py", line 190, in handlerWrapper
if params.get('action', '') == 'requestPermission':
UnboundLocalError: local variable 'params' referenced before assignment

Switching to new Tor identity on Android using QPython

After successfully installing QPython and Orbot on my Android device, I've pip-installed a well-known stem library and tried to use it for changing Tor identity by sending NEWNYM signal to control port.
On PC, this code
from stem.control import Controller
from stem import Signal
with Controller.from_port(port=9051) as ctrl:
ctrl.authenticate()
ctrl.signal(Signal.NEWNYM)
works perfectly.
But, on Android device, QPython returns an error:TypeError: decode() argument 1 must be string, not None. Authentication fails.
How could I overcome this problem? Maybe, I should look towards AnroidFacade SL4A API to interact with Tor?
I'am running Android 7.1 at Nokia 3. ControlPort was set to constantly be 9051 by using Torrc Custom Config in Orbot Settings.
Upd Here's a traceback stack:
/data/user/0/org.qpython.qpy/files/bin/qpython-android5.sh "/storage/emulated/0/qpython/scripts/new.py" && exit
d/0/qpython/scripts/new.py" && exit <
Traceback (most recent call last):
File "/storage/emulated/0/qpython/scripts/new.py", line 6, in <module>
ctrl.authenticate()
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/stem-1.6.0-py2.7.egg/stem/control.py", line 1092, in authenticate
stem.connection.authenticate(self, *args, **kwargs)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/stem-1.6.0-py2.7.egg/stem/connection.py", line 530, in authenticate
protocolinfo_response = get_protocolinfo(controller)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/stem-1.6.0-py2.7.egg/stem/connection.py", line 1022, in get_protocolinfo
stem.response.convert('PROTOCOLINFO', protocolinfo_response)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/stem-1.6.0-py2.7.egg/stem/response/__init__.py", line 124, in convert
message._parse_message(**kwargs)
File "/data/user/0/org.qpython.qpy/files/lib/python2.7/site-packages/stem-1.6.0-py2.7.egg/stem/response/protocolinfo.py", line 110, in _parse_message
self.cookie_path = line.pop_mapping(True, True, get_bytes = True)[1].decode(sys.getfilesystemencoding())
TypeError: decode() argument 1 must be string, not None
1|NE1:/ $

Opening Firefox via Selenium in Jenkins

When trying to run a Python Selenium script via Jenkins, it crashes, with a very unhelpful exception - "selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 0"
The same Python script runs perfectly fine from outside Python.
I've reduced the script to a very, very basic one, simply launching Firefox -
from selenium import webdriver
if __name__ == "__main__":
print("Hello World")
driver = webdriver.Firefox()
driver.get("http://www.google.com")
driver.maximize_window()
driver.quit()
print("Goodbye World")
Output from cmd prompt:
>C:\Users\kipod>C:\python_projects\Ranger\_just_open_browser.py
>Hello World
>Goodbye World
Works fine.
Running as a Jenkins job:
>##Started by user anonymous
>Building in workspace C:\Program Files (x86)\Jenkins\workspace\Second Test
>[Second Test] $ cmd /c call >C:\Users\kipod\AppData\Local\Temp\jenkins3557827225974274191.bat
>
>C:\Program Files (x86)\Jenkins\workspace\Second Test>python >C:\python_projects\Ranger\_just_open_browser.py
>Hello World
>Traceback (most recent call last):
> File "C:\python_projects\Ranger\_just_open_browser.py", line 8, in <module>
> driver = webdriver.Firefox()
> File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\firefox\webdriver.py", line 154, in __init__
> keep_alive=True)
> File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
> self.start_session(desired_capabilities, browser_profile)
> File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
> response = self.execute(Command.NEW_SESSION, parameters)
> File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
> self.error_handler.check_response(response)
> File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
> **raise exception_class(message, screen, stacktrace)
>selenium.common.exceptions.WebDriverException: Message: Process unexpectedly >closed with status: 0**
>C:\Program Files (x86)\Jenkins\workspace\Second Test>exit 1
>Build step 'Execute Windows batch command' marked build as failure
>Finished: FAILURE
I suspect something is off with Jenkins's environment variables, but I have no idea what to check. And the exception is so unspecific ("I crashed. lols"), That I found nothing helpful on Google. And I've been searching for a while.
Versions:
Jenkins: 2.73.1
Python: 3.6.2
Geckodriver: 0.19.0
Selenium: 3.6.0
(Tried opening chrome instead of firefox - same behaviour.)
I think you need to run your python script using a jenkins slave configured to log on as a standard windows user account (for example "kipod") ? Make sure that auto login is set for the slave machine for the user account, in order to allow selenium to launch Firefox in a desktop.
Some documenation here: Step by step guide to set up master and slave machines on Windows

CherryPy running tut01 file on Windows

Bit of info: Python 3.2.3,
Cherrypy version 3.2.2. Windows 7 64-bit.
Installed Cherrypy, set up PATH with the right Python directory, etc. However, whenever I run the tutorial file (tut01, Hello world) or any other python file with the same code, I get the following output:
F:\Code>python helloworld.py [29/Nov/2012:22:37:22] ENGINE Listening
for SIGTERM. [29/Nov/2012:22:37:22] ENGINE Bus STARTING CherryPy
Checker: The Application mounted at '' has an empty config.
[29/Nov/2012:22:37:22] ENGINE Started monitor thread
'_TimeoutMonitor'. [29/Nov/2012:22:37:22] ENGINE Started monitor
thread 'Autoreloader'. [29/Nov/2012:22:37:22] ENGINE Error in 'start'
listener > Traceback (most recent call last): File
"C:\Python32\lib\site-packages\cherrypy\process\wspbus.py", line 197,
in publish
output.append(listener(*args, **kwargs)) File "C:\Python32\lib\site-packages\cherrypy_cpserver.py", line 150, in
start
self.httpserver, self.bind_addr = self.httpserver_from_self() File "C:\Python32\lib\site-packages\cherrypy\_cpserver.py", line 140,
in https erver_from_self
from cherrypy import _cpwsgi_server File "C:\Python32\lib\site-packages\cherrypy_cpwsgi_server.py", line 7, in
from cherrypy import wsgiserver File "C:\Python32\lib\site-packages\cherrypy\wsgiserver__init__.py", line
14, in
exec('from .wsgiserver3 import *') File "", line 1, in ImportError: No module named wsgiserver3
[29/Nov/2012:22:37:22] ENGINE Shutting down due to error in start
listener: Traceback (most recent call last): File
"C:\Python32\lib\site-packages\cherrypy\process\wspbus.py", line 235,
in start
self.publish('start') File "C:\Python32\lib\site-packages\cherrypy\process\wspbus.py", line 215,
in publish
raise exc cherrypy.process.wspbus.ChannelFailures: ImportError('No module named wsgiserver 3',)
[29/Nov/2012:22:37:22] ENGINE Bus STOPPING [29/Nov/2012:22:37:22]
ENGINE HTTP Server None already shut down [29/Nov/2012:22:37:22]
ENGINE Stopped thread 'Autoreloader'. [29/Nov/2012:22:37:22] ENGINE
Stopped thread '_TimeoutMonitor'. [29/Nov/2012:22:37:22] ENGINE Bus
STOPPED [29/Nov/2012:22:37:22] ENGINE Bus EXITING
[29/Nov/2012:22:37:22] ENGINE Bus EXITED
And pointing browser to localhost:8080 does nothing, when it should show Hello World.
Pretty sure I did everything correctly according to the installation guide on the Cherrypy website. Not entirely sure how to fix it, but I'm guessing it has something to do with the import errors. Has anyone else had success with installing cherrypy on windows for python3?
Found a solution: https://bitbucket.org/cherrypy/cherrypy/issue/1110/cherrypy-322win32exe-installer-didnt
The original installer was missing the wsgiserver3 module, which was needed for it to work on Python 3.x. The above installer should fix the issue.
I struggled with this, there is a simple solution:
clone the repository to your local machine.
navigate to the root folder and execute the following command: python setup.py install
It is mentioned in the README.txt here in the official source repo.
Just to notice that this is a answered question, quoting rashdanml:
Found a solution: https://bitbucket.org/cherrypy/cherrypy/issue/1110/cherrypy-322win32exe-installer-didnt?
The original installer was missing the wsgiserver3 module, which was needed for it to work on Python 3.x. The above installer should fix the issue.

Hello world failing

I've just installed python 3.2.1 (32-bit) and cherrypy 3.2.1 (CherryPy-3.2.1.win32-py3.exe) on my Windows 7 box and have tried the hello world example (executed via PyScripter) but it hangs after the Engine bus STARTED message.
If I try to start it via the python.exe, I get the following log:
C:\Program Files (x86)\Python32>python hello.py
[24/Jul/2011:16:24:03] ENGINE Listening for SIGTERM.
[24/Jul/2011:16:24:03] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.
[24/Jul/2011:16:24:03] ENGINE Started monitor thread 'Autoreloader'.
[24/Jul/2011:16:24:03] ENGINE Started monitor thread '_TimeoutMonitor'.
[24/Jul/2011:16:24:03] ENGINE Serving on 127.0.0.1:8080
[24/Jul/2011:16:24:03] ENGINE Bus STARTED
Exception in thread CP Server Thread-4:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 693, in read_request_headers
read_headers(self.rfile, self.inheaders)
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 202, in read_headers
raise ValueError("Illegal end of headers.")
ValueError: Illegal end of headers.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 1024, in communicate
req.parse_request()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 578, in parse_request
success = self.read_request_headers()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 696, in read_request_headers
self.simple_response("400 Bad Request", ex.args[0])
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 840, in simple_response
status = str(status)
TypeError: 'tuple' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python32\lib\threading.py", line 736, in _bootstr
ap_inner
self.run()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 1174, in run
conn.communicate()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 1080, in communicate
req.simple_response("500 Internal Server Error", format_exc())
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 840, in simple_response
status = str(status)
TypeError: 'tuple' object is not callable
What am I missing?
Code:
import cherrypy
class HelloWorld:
def index(self):
return "Hello world"
index.exposed = True
cherrypy.quickstart(HelloWorld())
EDIT: Bonus-info: I've tried various things to remedy the situation with no result. Installing the 64-bit version of python didn't help as cherrypy doesn't support 64-bit (unless, I'm mistaken). I've tried re-installing both python and the cherrypy packages, and I've tried deactivating all other things that might block it (IIS). All to no avail :-(
EDIT2: Second bonus - everything works if I install it with python 2.7.2, so seems it is only a problem with 3.x (I've tried 3.0.1 as well - same problem)
I have encountered two errors:
1 - open your browser before starting the script, so you'll not have any problem.
2 - if you use a personal firewall or an antivirus that handles HTTP protection, be sure he is not protecting the 8080 port, for example ESET Antivirus will not let you use the 8080 and CherryPy will say that the port is not free.

Resources