Switching to new Tor identity on Android using QPython - tor

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:/ $

Related

Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist

Running a script here that connects to 2 Bluetooth adapters and collects data to send via mqtt. Its been running relatively smoothly on my RPi Zero 2 W with LM1010 BT USB adapter (internal wifi and BT adapter for RPi are disabled) for about 2 years now. However, yesterday, I ran just your normal system updates 'sudo apt-get update then upgrade', now when I try to run the script, I get these errors.
I don't know even where to start with this one, and if you can provide some suggestions, that would be great.
INFO: Adapter status - Powered: True
INFO: Starting discovery...
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/gatt/gatt_linux.py", line 156, in stop_discovery
self._adapter.StopDiscovery()
File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 141, in __call__
return self._connection.call_blocking(self._named_service,
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/solar-monitor/solar-monitor.py", line 84, in <module>
device_manager.stop_discovery()
File "/home/pi/.local/lib/python3.9/site-packages/gatt/gatt_linux.py", line 161, in stop_discovery
raise _error_from_dbus_error(e)
gatt.errors.Failed: Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
ran script, but seems to crash at BLE scan part now after system updates

python webbrowser module not working on mac 16.2.1

I'm trying to use the webbrowser module to open a web page.
The first attempt leads to nowhere. code hangs, nothing happens.
After a keyboard interrupt the same command - and everything works just fine.
>>> import webbrowser
>>> webbrowser._browsers
{}
>>> webbrowser.register_standard_browsers()
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python#3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/webbrowser.py", line 555, in register_standard_browsers
raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
File "/usr/local/Cellar/python#3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 421, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,File "/usr/local/Cellar/python#3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 505, in run
stdout, stderr = process.communicate(input, timeout=timeout)
File "/usr/local/Cellar/python#3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1141, in communicate
stdout = self.stdout.read()
KeyboardInterrupt
>>> webbrowser._browsers
{'macosx': [None, <webbrowser.MacOSXOSAScript object at 0x10f08c5e0>], 'chrome': [None, <webbrowser.MacOSXOSAScript object at 0x10f08c670>], 'firefox': [None, <webbrowser.MacOSXOSAScript object at 0x10f08c760>], 'safari': [None, <webbrowser.MacOSXOSAScript object at 0x10efb4370>]}
Traceback tells me it stucks somewhere in the register process.
So i tried to register all standard browsers -> same behavior. But after keyboard interrupt webbrowser._browsers returned registered browsers.
Tried to register chrome browser - also the same.
webbrowser._browsers['chrome'][1].open("https://www.google.com/")
also needs an interrupt but that command opens the site directly after keyboard interrupt
Problem is the same from py version 3.9 - 3.11. Also on pycharm within or without a virtual environment.
Can anybody reproduce this or tell me what's going on?

Failed to create a device file using `uinput` module. Python3 on Ubuntu for Windows

I have a python script that runs on python3.4 and uses the package keyboard to allow for keybinds;
keyboard.add_hotkey("enter", self.listener.stop, suppress=True)
keyboard.add_hotkey("shift+enter", self.listener.finish, suppress=True)
When I run this on Windows, it works perfectly listening to both hotkeys, also when run on linux (CentOS) it works.
At work I've gotten a Ubuntu environment on my windows via the windows 10 feature and app store. However this environment has a problem with this keyboard hotkey.
/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixkeyboard.py:110: UserWarning: Failed to create a device file using `uinput` module. Sending of events may be limited or unavailable depending on plugged-in devices.
device = aggregate_devices('kbd')
Traceback (most recent call last):
File "main.py", line 32, in <module>
], 'test')
File "/mnt/.../can_controller.py", line 28, in __init__
self.__initialise_key_handler()
File "/mnt/.../can_controller.py", line 95, in __initialise_key_handler
keyboard.add_hotkey("enter", self.listener.stop, suppress=True)
File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/__init__.py", line 637, in add_hotkey
_listener.start_if_necessary()
File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/__init__.py", line 194, in init
_os_keyboard.init()
File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixkeyboard.py", line 110, in build_device
device = aggregate_devices('kbd')
File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixcommon.py", line 168, in aggregate_devices
assert fake_device
AssertionError
If anybody knows how to fix this or has a good work-around. Please let me know.

pexpect telnet on windows

I've used pexpect on linux successfully to telnet/ssh into Cisco switches for CLI scrapping. I'm trying to convert this code over to Windows and having some issues since it doesn't support the pxpect.spawn() command.
I read some online documentation and it suggested to use the pexpect.popen_spawn.PopenSpawn command. Can someone please point to me what I'm doing wrong here? I removed all my exception handling to simplify the code. Thanks.
import pexpect
from pexpect.popen_spawn import PopenSpawn
child = pexpect.popen_spawn.PopenSpawn('C:/Windows/System32/telnet 192.168.1.1')
child.expect('Username:')
child.sendline('cisco')
child.expect('Password:')
child.sendline('cisco')
child.expect('>')
child.close()
Error:
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\expect.py", line 98, in expect_loop
incoming = spawn.read_nonblocking(spawn.maxread, timeout)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\popen_spawn.py", line 68, in read_nonblocking
raise EOF('End Of File (EOF).')
pexpect.exceptions.EOF: End Of File (EOF).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python\windows scripts\telnet\telnet.py", line 37, in <module>
main()
File "C:\Python\windows scripts\telnet\telnet.py", line 20, in main
child.expect('Username:')
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\spawnbase.py", line 327, in expect
timeout, searchwindowsize, async_)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\spawnbase.py", line 355, in expect_list
return exp.expect_loop(timeout)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\expect.py", line 104, in expect_loop
return self.eof(e)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\expect.py", line 50, in eof
raise EOF(msg)
pexpect.exceptions.EOF: End Of File (EOF).
<pexpect.popen_spawn.PopenSpawn object at 0x000000000328C550>
searcher: searcher_re:
0: re.compile("b'Username:'")
The solution is to use plink.exe, which is a part of putty installation. You can download it from https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Enable TelnetClient on windows system and put plink.exe in the same folder from where you are running pexpect. Then you can telnet using pexpect as mentioned in the below example.
Also, use timeout flag with PopenSpawn to wait for the connection to establish. The above error is due to a timeout flag is not set.
p = pexpect.popen_spawn.PopenSpawn('plink.exe -telnet 192.168.0.1 -P 23', timeout=1)

Phone Book Access (PBAP) client for Linux (Raspberry Pi)

i want to access the contacts of my smartphone over bluetooth. This should be made as first step of a project of my with a raspberry pi. I read something about the phone bok access protocol (PBAP).
But all i could was not very helpful for me. The most examples i found where to old.
I already managed to pair and connect my smart phone (OnePlus One). I also can see that is support PBAP. I use bluez in version 5.23-2+rpi1.
I found two examples of an PBAP client, one from obexd (http://code.metager.de/source/xref/linux/bluetooth/obexd/test/pbap-client) and one from bluez (http://code.metager.de/source/xref/linux/bluetooth/bluez/test/pbap-client).
If i execute the obexd example on the pi i get the following error:
Creating Session
Traceback (most recent call last):
File "pbap-client-obexd.py", line 110, in <module>
session_path = client.CreateSession(sys.argv[1], { "Target": "PBAP" })
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.bluez.obex.Error.Failed: No adapter found
If i execute the bluez example i get the following error:
Creating Session
Traceback (most recent call last):
File "pbap-client-bluez.py", line 128, in <module>
session_path = client.CreateSession(sys.argv[1], { "Target": "PBAP" })
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: Method "CreateSession" with signature "sa{ss}" on interface "org.bluez.obex.Client1" doesn't exist
Does anyone of you have an idea to fix it, an actual tutorial or an other example?
Thank you
After searching a few hours later, i found a python library called PyOBEX. It contains some examples, e.g. a PBAP-Client, a example to download files over bluetooth and much more. It also contains all methods for pairing and connecting. Works on first try for me.
Link:
https://bitbucket.org/dboddie/pyobex/overview
PyOBEX is the right choice. you can also have a look into pypbap which has both pbap client and server built on top of PyOBEX. And has nice REPL to playaround with all pbap functionalities.

Resources