i have a problem:
This is the run function after I click on the kivy button
And I know that time.sleep is used badly here, but how can I possibly
replace it?
from jnius import autoclass
def run(self):
self.r = MyRecorder()
self.r.mRecorder.prepare()
self.r.mRecorder.start()
self.console.text += "Recording.."
time.sleep(1)
self.r.mRecorder.stop()
self.r.mRecorder.release()
self.console.text += "Recording stopped.."
This is the recorder class (Is everything right?)
class MyRecorder:
def __init__(self):
'''Recorder object To access Android Hardware'''
self.MediaRecorder = autoclass('android.media.MediaRecorder')
self.AudioSource = autoclass('android.media.MediaRecorder$AudioSource')
self.OutputFormat = autoclass('android.media.MediaRecorder$OutputFormat')
self.AudioEncoder = autoclass('android.media.MediaRecorder$AudioEncoder')
# create out recorder
self.mRecorder = self.MediaRecorder()
self.mRecorder.setAudioSource(self.AudioSource.MIC)
self.mRecorder.setOutputFormat(self.OutputFormat.THREE_GPP)
self.mRecorder.setAudioEncoder(self.AudioEncoder.AMR_NB)
self.mRecorder.setOutputFile('./MYAUDIO.3gp')
Here's the error I got:
if child.dispatch('on_touch_down', touch): File "kivy/_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
self.dispatch('on_press') File "kivy/_event.pyx", line 705, in kivy._event.EventDispatcher.dispatch File "kivy/_event.pyx", line 1248, in kivy._event.EventObservers.dispatch File "kivy/_event.pyx", line 1132, in kivy._event.EventObservers._dispatch File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivy/lang/builder.py", line 57, in custom_callback
exec(kvlang.co_value, idmap) File "/storage/emulated/0/python/my.kv", line 6, in <module>
on_press: root.run() File "/storage/emulated/0/python/main.py", line 51, in run
startRecording(self) File "/storage/emulated/0/python/main.py", line 139, in init
self.mRecorder.setOutputFile('./MYAUDIO.3gp') File "jnius/jnius_export_class.pxi", line 857, in jnius.jnius.JavaMethod.call File "jnius/jnius_export_class.pxi", line 954, in jnius.jnius.JavaMethod.call_method File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception jnius.jnius.JavaException: JVM exception occurred: setAudioSource failed. java.lang.RuntimeException
Can anyone help me please? Thanks!
I don't have a lot of experience in Kivy, but based on my experience developing some native android Apps, looks like you didn't ask for record audio permission on your code.
Based on this video (start on 27:48), you need to request access putting on your code something like:
from android.permissions import Permission, request_permissions
def callback_func(permission, results):
if all([res for res in results):
print("All permissions granted")
else:
print("Did not get all permissions")
request_permissions([Permission.RECORD_AUDIO], callback_func)
Remember to ask for the record permission BEFORE using the microphone.
You can read all the permissions here.
Related
I have a Pyrogram app that has been running for ages with no problems from a server running MacOS. A few days ago, the code suddenly hung up and refuses to work. As soon as I attempt to start the Pyrogram Client(), I immediately get "Err 61 Connection Refused"/"network issues" errors. I have confirmed that my Telegram API account is totally fine. The next assumption was that it was an IP ban issue, but I can't even get the Client to open a socket to an http proxy. Pyrogram documentation has nothing about an Error 61, and now I'm thinking that the problem isn't with Pyrogram but rather with a core Python library (corrupted?).
I have seen references on Stackoverflow to folks running into analogous problems with other Python api/web applications but not randomly after a year of normal operation. Some of them were able to resolve the issue by switching references to "localhost" to "127.0.0.1", but I have no idea where that would be located within the Pyrogram library, nor why that would suddenly be a problem out of the blue with no code or server changes.
Help! ;) Thanks!!
Update:
I forgot to post code:
import os
import logging
from typing import List, Tuple, Optional
import re
import math
from datetime import datetime
import os.path
import asyncio
import pyrogram
import yaml
import time
import base64
import sys
import mysql.connector
import subprocess
client = pyrogram.Client(
"media_downloader",
api_id,
api_hash,
)
... and there it ends.
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 61] Connection refused
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 61] Connection refused
INFO:pyrogram.connection.connection:Connecting...
^CTraceback (most recent call last):
File "/Users/admin/home/telegram/get_message_media_v2.py", line 99, in <module>
with client:
File "/usr/local/lib/python3.9/site-packages/pyrogram/client.py", line 251, in __enter__
return self.start()
File "/usr/local/lib/python3.9/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
self.run_forever()
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
self._run_once()
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1854, in _run_once
event_list = self._selector.select(timeout)
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py", line 562, in select
kev_list = self._selector.control(None, max_ev, timeout)
KeyboardInterrupt
After attempting with a proxy:
INFO:pyrogram.connection.transport.tcp.tcp:Using proxy [PROXY REDACTED]
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: Socket error: timed out
INFO:pyrogram.connection.transport.tcp.tcp:Using proxy [PROXY REDACTED]
INFO:pyrogram.connection.connection:Connecting...
^X^CTraceback (most recent call last):
File "/Users/admin/home/telegram/get_message_media_v2.py", line 106, in <module>
with client:
File "/usr/local/lib/python3.9/site-packages/pyrogram/client.py", line 251, in __enter__
return self.start()
File "/usr/local/lib/python3.9/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
self.run_forever()
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
self._run_once()
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
handle._run()
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.9/site-packages/pyrogram/methods/utilities/start.py", line 52, in start
is_authorized = await self.connect()
File "/usr/local/lib/python3.9/site-packages/pyrogram/methods/auth/connect.py", line 46, in connect
await self.session.start()
File "/usr/local/lib/python3.9/site-packages/pyrogram/session/session.py", line 105, in start
await self.connection.connect()
File "/usr/local/lib/python3.9/site-packages/pyrogram/connection/connection.py", line 57, in connect
await self.protocol.connect(self.address)
File "/usr/local/lib/python3.9/site-packages/pyrogram/connection/transport/tcp/tcp_abridged_o.py", line 40, in connect
await super().connect(address)
File "/usr/local/lib/python3.9/site-packages/pyrogram/connection/transport/tcp/tcp.py", line 82, in connect
self.socket.connect(address)
File "/usr/local/lib/python3.9/site-packages/socks.py", line 47, in wrapper
return function(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/socks.py", line 809, in connect
negotiate(self, dest_addr, dest_port)
File "/usr/local/lib/python3.9/site-packages/socks.py", line 443, in _negotiate_SOCKS5
self.proxy_peername, self.proxy_sockname = self._SOCKS5_request(
File "/usr/local/lib/python3.9/site-packages/socks.py", line 470, in _SOCKS5_request
chosen_auth = self._readall(reader, 2)
File "/usr/local/lib/python3.9/site-packages/socks.py", line 276, in _readall
d = file.read(count - len(data))
File "/usr/local/Cellar/python#3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
If anyone else runs into this problem, I was able to eventually resolve this by using pip3 to reinstall/upgrade Pyrogram. I still don't know the exact underlying cause, and at this point, I can only assume that either my copy of Pyrogram got corrupted somehow, or else there were changes to Telegram that broke a slightly older version of Pyrogram (I had 1.7.1 installed previously and pip upgraded it to 2.0.35).
pip3 install pyrogram --upgrade
After running the codes provided in the tutorial of justpy
import justpy as jp
def my_click(self, msg):
self.text = 'I was clicked'
def event_demo():
wp = jp.WebPage()
d = jp.Div(text='Not clicked yet', a=wp, classes='w-48 text-xl m-2 p-1 bg-blue-500 text-white')
d.on('click', my_click)
return wp
jp.justpy(event_demo)
I received the following errors whenever I opening the webpage on 127.0.0.1:8000. The layout of the webpage can be rendered properly, but the events of the elements cannot, i.e. the element can't be clicked.
JustPy ready to go on http://127.0.0.1:8000
ERROR base_events: Exception in callback _ProactorReadPipeTransport._loop_reading(<_OverlappedF...bits\r\n\r\n'>)
handle: <Handle _ProactorReadPipeTransport._loop_reading(<_OverlappedF...bits\r\n\r\n'>)>
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 318, in _loop_reading
self._data_received(data)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 269, in _data_received
self._protocol.data_received(data)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 124, in data_received
self.handle_events()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 173, in handle_events
self.handle_upgrade(event)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 245, in handle_upgrade
protocol = self.ws_protocol_class(
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 62, in __init__
super().__init__(
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\legacy\server.py", line 201, in __init__
super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'logger'
May I ask why it happens and how it can be solved? Thanks for your patience and sorry for my bad English.
I am very new to RabbitMQ. I use Python to send a message between the Sender.py and Receiver.py (from the Rabbit tutorial). It works well if I run the Sender.py and Receiver.py independtly. However, I want to make the third file, namely, RunToGether.py with very very simple code:
import Sender, Receiver
Sender.send()
Receiver.receive()
and it crashes:
File "/home/my_direct/Receive.py", line 50, in PV_simulator
channel.start_consuming()
File "/home/my_direct/venv/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 1865, in start_consuming
self._process_data_events(time_limit=None)
File "/home/rmy_direct/venv/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 2026, in _process_data_events
self.connection.process_data_events(time_limit=time_limit)
File "/home/my_direct/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 824, in process_data_events
self._flush_output(common_terminator)
File "/home/my_direct/venv/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 514, in _flush_output
self._impl.ioloop.poll()
File "/home/my_direct/venv/lib/python3.8/site-packages/pika/adapters/select_connection.py", line 579, in poll
self._poller.poll()
File "/home/my_direct/venv/lib/python3.8/site-packages/pika/adapters/select_connection.py", line 1184, in poll
events = self._poll.poll(self._get_max_wait())
KeyboardInterrupt
Please help!
I am trying to use python Zeep library in order to play with some SOAP API. But I can not figure out what is my issue when trying to create the client. Below is a sample of my code:
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep import Client, Settings
from zeep.cache import SqliteCache
from zeep.transports import Transport
from conf.shared_vars import B2B_PROXY, WSDL_PROXY
session = Session()
session.auth = HTTPBasicAuth(B2B_PROXY['key'], B2B_PROXY['secret'])
wsdl = WSDL_PROXY + "SomeServices.wsdl"
client = Client(
wsdl=wsdl,
transport=Transport(
session=session,
cache=SqliteCache(path='./sqlite.db')))
When executing that script, it seems to load data (./sqlite is not empty), but I get the following error (traceback):
File "test_zeep.py", line 17, in <module>
cache=SqliteCache(path='./sqlite.db')))
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/client.py", line 68, in __init__
self.wsdl = Document(wsdl, self.transport, settings=self.settings)
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/wsdl/wsdl.py", line 82, in __init__
root_definitions = Definition(self, document, self.location)
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/wsdl/wsdl.py", line 184, in __init__
self.parse_types(doc)
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/wsdl/wsdl.py", line 316, in parse_types
self.types.add_documents(schema_nodes, self.location)
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/schema.py", line 117, in add_documents
document.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/schema.py", line 451, in resolve
schema.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/schema.py", line 451, in resolve
schema.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/schema.py", line 451, in resolve
schema.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/schema.py", line 475, in resolve
_resolve_dict(self._elements)
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/schema.py", line 456, in _resolve_dict
new = obj.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/element.py", line 301, in resolve
self.resolve_type()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/element.py", line 298, in resolve_type
self.type = self.type.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/types/unresolved.py", line 23, in resolve
return retval.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/types/complex.py", line 355, in resolve
self._resolved = self.extend(self._extension)
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/types/complex.py", line 401, in extend
self._element = self._element.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/indicators.py", line 213, in resolve
self[i] = elm.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/element.py", line 301, in resolve
self.resolve_type()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/element.py", line 298, in resolve_type
self.type = self.type.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/types/unresolved.py", line 23, in resolve
return retval.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/types/complex.py", line 361, in resolve
self._element = self._element.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/indicators.py", line 213, in resolve
self[i] = elm.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/element.py", line 301, in resolve
self.resolve_type()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/elements/element.py", line 298, in resolve_type
self.type = self.type.resolve()
File "/home/max/Documents/dev/django/nmtoolpy/venv/lib/python3.6/site-packages/zeep/xsd/types/collection.py", line 21, in resolve
self.item_type = self.item_type.resolve()
AttributeError: 'lxml.etree.QName' object has no attribute 'resolve'
Unfortunately, I do not know what do with this information, what it involves and how to overcome the issue so I can use properly the client!
Thanks for the help you could offer me on this topic.
Well one way to get through this is to modify the involved method in zeep/xsd/types/collection.py:
def resolve(self):
try:
self.item_type = self.item_type.resolve()
except Exception:
print("No resolve method for {}".format(self.item_type))
self.base_class = self.item_type.__class__
return self
This is just a fix and definitly not the best solution, but at least it allows me to use properly Zeep client! I will fill an issue on Zeep GitHub.
I'm learning python (from a very low baseline) and recently re-installed Canopy (on a MacBook) It was working fine before.
Now whenever I try an launch the editor I get a Access Denied error.
Can anyone help? Please bear in mind my inexperience
Thanks
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/envisage/ui/tasks/tasks_application.py", line 205, in create_window
window.add_task(task)
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/pyface/tasks/task_window.py", line 187, in add_task
state.dock_panes.append(dock_pane_factory(task=task))
File "build/bdist.macosx-10.5-i386/egg/canopy/plugin/editor_task.py", line 143, in _create_python_pane
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/envisage/application.py", line 371, in get_service
protocol, query, minimize, maximize
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/envisage/service_registry.py", line 78, in get_service
services = self.get_services(protocol, query, minimize, maximize)
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/envisage/service_registry.py", line 115, in get_services
actual_protocol, name, obj, properties, service_id
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/envisage/service_registry.py", line 259, in _resolve_factory
obj = obj(**properties)
File "build/bdist.macosx-10.5-i386/egg/canopy/python_frontend/plugin.py", line 109, in _frontend_manager_service_factory
File "build/bdist.macosx-10.5-i386/egg/canopy/app/running_process_manager.py", line 82, in register_proc
File "build/bdist.macosx-10.5-i386/egg/canopy/app/util.py", line 53, in get_exe_or_cmdline
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/psutil/_common.py", line 80, in get
ret = self.func(instance)
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/psutil/init.py", line 331, in exe
return guess_it(fallback=err)
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/psutil/init.py", line 314, in guess_it
cmdline = self.cmdline
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/psutil/init.py", line 346, in cmdline
return self._platform_impl.get_process_cmdline()
File "/Users/simonthompson/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/psutil/_psosx.py", line 153, in wrapper
raise AccessDenied(self.pid, self._process_name)
AccessDenied: (pid=343)
DEBUG|2013-11-03 21:19:25|QtWarningMsg: QImage::scaled: Image is a null image
Since the supplied information is insufficient, the answer is the same. This is about user authentication. I don't know how you open the app but, your app tries to open a file or a process which is could not be opened by your user. If you open your app with root privileges there won't be any problem.