Error connecting to simulator: "Missing the \'authorization\' header with security credentials"
Hi I am trying to create a simple environment with:
from android_env import loader
env = loader.load(
avd_name='Pixel_3a_API_34_extension_level_7_arm64-v8a',
# avd_name='my_avd',
android_avd_home='/Users/anujm/.android/avd',
android_sdk_root='/Users/anujm/Library/Android/sdk',
emulator_path='/Users/anujm/Library/Android/sdk/emulator/emulator',
adb_path='/Users/anujm/Library/Android/sdk/platform-tools/adb',
task_path='/Users/anujm/code/android_env/tasks/mdp/mdp_0000.textproto',
)
but I run into "Missing the 'authorization' header with security credentials"
ERROR:absl:RpcError caught. Reconnecting to emulator...
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py", line 87, in wrapper
return func(*args, **kwargs) # pytype: disable=missing-parameter # always-use-return-annotations
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py", line 373, in _confirm_booted
emu_status = self._emulator_stub.getStatus(empty_pb2.Empty())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py", line 1176, in __call__
return _end_unary_response_blocking(state, call, False, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py", line 1005, in _end_unary_response_blocking
raise _InactiveRpcError(state) # pytype: disable=not-instantiable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Missing the 'authorization' header with security credentials."
debug_error_string = "UNKNOWN:Error received from peer {created_time:"2024-03-27T18:30:09.412245-07:00", grpc_status:16, grpc_message:"Missing the \'authorization\' header with security credentials."}"
>
Below is the caller stack trace:
{
"name": "SimulatorError",
"message": "Exception caught in simulator. Please see the simulator logs above for more details.",
"stack": "---------------------------------------------------------------------------
_InactiveRpcError Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py:87, in _reconnect_on_grpc_error.<locals>.wrapper(*args, **kwargs)
86 try:
---> 87 return func(*args, **kwargs) # pytype: disable=missing-parameter # always-use-return-annotations
88 except grpc.RpcError:
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py:373, in EmulatorSimulator._confirm_booted(self, startup_wait_time_sec)
372 while time.time() < deadline:
--> 373 emu_status = self._emulator_stub.getStatus(empty_pb2.Empty())
374 logging.info('Waiting for emulator (%r) to start... (%rms)',
375 self.adb_device_name(), emu_status.uptime)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:1176, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
1170 (
1171 state,
1172 call,
1173 ) = self._blocking(
1174 request, timeout, metadata, credentials, wait_for_ready, compression
1175 )
-> 1176 return _end_unary_response_blocking(state, call, False, None)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:1005, in _end_unary_response_blocking(state, call, with_call, deadline)
1004 else:
-> 1005 raise _InactiveRpcError(state)
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
\tstatus = StatusCode.UNAUTHENTICATED
\tdetails = \"Missing the 'authorization' header with security credentials.\"
\tdebug_error_string = \"UNKNOWN:Error received from peer {created_time:\"2024-03-27T18:30:09.412245-07:00\", grpc_status:16, grpc_message:\"Missing the \\'authorization\\' header with security credentials.\"}\"
>
During handling of the above exception, another exception occurred:
_InactiveRpcError Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/base_simulator.py:32, in _print_logs_on_exception.<locals>.wrapper(*args, **kwargs)
31 try:
---> 32 return func(*args, **kwargs)
33 except Exception as error:
34 # Calls self.get_logs since self is the first arg.
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/base_simulator.py:83, in BaseSimulator.launch(self)
82 self._num_launch_attempts += 1
---> 83 self._launch_impl()
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py:250, in EmulatorSimulator._launch_impl(self)
249 try:
--> 250 self._confirm_booted()
251 except EmulatorCrashError:
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py:94, in _reconnect_on_grpc_error.<locals>.wrapper(*args, **kwargs)
91 emu._emulator_stub, emu._snapshot_stub = emu._connect_to_emulator( # pylint: disable=protected-access
92 emu._grpc_port # pylint: disable=protected-access
93 )
---> 94 return func(*args, **kwargs)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/emulator/emulator_simulator.py:373, in EmulatorSimulator._confirm_booted(self, startup_wait_time_sec)
372 while time.time() < deadline:
--> 373 emu_status = self._emulator_stub.getStatus(empty_pb2.Empty())
374 logging.info('Waiting for emulator (%r) to start... (%rms)',
375 self.adb_device_name(), emu_status.uptime)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:1176, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
1170 (
1171 state,
1172 call,
1173 ) = self._blocking(
1174 request, timeout, metadata, credentials, wait_for_ready, compression
1175 )
-> 1176 return _end_unary_response_blocking(state, call, False, None)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:1005, in _end_unary_response_blocking(state, call, with_call, deadline)
1004 else:
-> 1005 raise _InactiveRpcError(state)
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
\tstatus = StatusCode.UNAUTHENTICATED
\tdetails = \"Missing the 'authorization' header with security credentials.\"
\tdebug_error_string = \"UNKNOWN:Error received from peer {created_time:\"2024-03-27T18:30:09.418329-07:00\", grpc_status:16, grpc_message:\"Missing the \\'authorization\\' header with security credentials.\"}\"
>
The above exception was the direct cause of the following exception:
SimulatorError Traceback (most recent call last)
Cell In[1], line 3
1 from android_env import loader
----> 3 env = loader.load(
4 avd_name='Pixel_3a_API_34_extension_level_7_arm64-v8a',
5 # avd_name='my_avd',
6 android_avd_home='/Users/anujm/.android/avd',
7 android_sdk_root='/Users/anujm/Library/Android/sdk',
8 emulator_path='/Users/anujm/Library/Android/sdk/emulator/emulator',
9 adb_path='/Users/anujm/Library/Android/sdk/platform-tools/adb',
10 task_path='/Users/anujm/code/android_env/tasks/mdp/mdp_0000.textproto',
11 )
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/loader.py:72, in load(task_path, avd_name, android_avd_home, android_sdk_root, emulator_path, adb_path, run_headless)
69 text_format.Parse(proto_file.read(), task)
71 task_manager = task_manager_lib.TaskManager(task)
---> 72 coordinator = coordinator_lib.Coordinator(simulator, task_manager)
74 # Load environment.
75 return environment.AndroidEnv(coordinator=coordinator)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/coordinator.py:120, in Coordinator.__init__(self, simulator, task_manager, num_fingers, interaction_rate_sec, enable_key_events, show_touches, show_pointer_location, show_status_bar, show_navigation_bar, periodic_restart_time_min, tmp_dir)
117 self._simulator_start_time = None
119 logging.info('Starting the simulator...')
--> 120 self._launch_simulator()
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/coordinator.py:223, in Coordinator._launch_simulator(self, max_retries)
220 self._task_manager.stop()
222 # Launch the simulator.
--> 223 self._simulator.launch()
224 self._simulator_start_time = time.time()
226 # From here on, the simulator is assumed to be up and running.
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/android_env/components/simulators/base_simulator.py:37, in _print_logs_on_exception.<locals>.wrapper(*args, **kwargs)
35 for line in args[0].get_logs().splitlines():
36 logging.error(line)
---> 37 raise errors.SimulatorError(
38 'Exception caught in simulator. Please see the simulator logs '
39 'above for more details.') from error
SimulatorError: Exception caught in simulator. Please see the simulator logs above for more details."
}
Any help would be great, Thanks
Hi @AnujMahajanOxf,
One internal Google client encountered this a while ago, and it was due to not passing -grpc. Can you set grpc_port when loading the environment? Also, it seems like you're using an old version of the loader, please use this: https://github.com/google-deepmind/android_env/blob/main/android_env/loader.py (from the github version, not pip. We haven't updated that).
Let me know how it goes. Cheers
Hi again,
I remembered that the port for gRPC is automatically picked, so you shouldn´t need to pass it.
I'd say, try using the version at HEAD and then you can come back with a new stack trace if any. Thanks!
I had this same issue on HEAD, turns out it was occurring since I had the emulator on in Android Studio while trying to start the python script. Should be fixed by simply turning off the emulator first.
This issue will be closed due to inactivity.