I am tryin to send desktop notifications with python, and was trying to run a test code but this error showed up. I have already installed pip and plyer. I am using a Mac if it helps.
For reference, I was following this tutorial
Code:
from plyer import notification
notification.notify(
title = 'testing',
message = 'message',
app_icon = None,
timeout = 10,
)
Please do let me know if I did anything wrong.
As the exception says, it is not implemented.
You can see it in the code here:
self._notify(
title=title, message=message,
app_icon=app_icon, app_name=app_name,
timeout=timeout, ticker=ticker, toast=toast, hints=hints
)
# private
def _notify(self, **kwargs):
raise NotImplementedError("No usable implementation found!")
Related
I am developing a little bot in python with the library python-telegram-bot, and I am stucked with a little problem :
I have an InlineKeyboardButton with the parameter switch_inline_query_current_chat, so when the user click on it, a command is automatically written in its chat.
But, that command is preceded with the mention of the bot (with an #).
The problem is my bot isn't answering in that case, and I have no idea why..
Is there a solution to make the button do not preced the command with the mention of the bot ?
From #BotFather the groups are allowed and the privacy group is turned off.
Thank you a lot
Edit : This is the code for the CommandHandler :
def getEntry(update, context):
if not (is_allowed_user(update.message.from_user.username, 'getEntry')):
context.bot.send_message(chat_id=update.effective_chat.id,
text='Who the hell are you #' + update.message.from_user.username + ' ?')
return
search = ' '.join(context.args)
infos, err = get_infos_people(search)
if err is not None:
context.bot.send_message(chat_id=update.effective_chat.id, text=err)
return
context.bot.send_message(chat_id=update.effective_chat.id, text=beautify_infos(infos),
parse_mode=ParseMode.MARKDOWN, reply_markup=getMainKeyboard(infos))
get_handler = CommandHandler('get', getEntry, filters=~Filters.update.edited_message)
And this is the code for the buttons :
def getMainKeyboard(infos):
keyboard = [InlineKeyboardButton("modify",
switch_inline_query_current_chat="/get " + infos[0] + "<write here>")]]
return InlineKeyboardMarkup(keyboard)
Note: I'm no python-telegram-bot expert, but the issue/fix should be non-lib related
Your commandHandler() is defined as so:
get_handler = CommandHandler('get', getEntry, filters=~Filters.update.edited_message)
This links the /get command to the getEntry handler.
Issue
Since the command is only fired at /get, you'll need to add a second command with the name of the bot so it will register that command as-well;
get_handler = CommandHandler([ 'get', 'get#myBot' ], getEntry, filters=~Filters.update.edited_message)
The first argument (command) accepts both a str or a list as the docs shows
Had the same issue in some other library, don't think there is a 'cleaner' way of handeling this.
so, i'm trying to use custom abort message while using SwaggerClient. when using flask restful abort function, i can see the abort message on the SwaggerUI. but when i'm trying to see the error message while using the python module, im getting bravado.exception error code.
i tried to use #namespace.response decorator, i tried to use "also_return_response": True, "disable_fallback_results": True and still, no hope.
i would love to get some help/hints etc..
some of my code:
_api = Api(_app, version='1.0', title=self.name, description=self.name, errors = errors, )
NAMESPACE = "test"
namespace = _api.namespace(NAMESPACE, description=NAMESPACE)
#namespace.route("/error")
class SystemStatus(Resource):
#namespace.doc("status")
# #namespace.response(409, "Missing Parameter")
def get(self):
_api.abort(409, "testError")
and the usage of the SwaggerCLient:
def testing2(self):
print("In testing2")
return self.swagger_client.test.status().response()
Error for example: bravado.exception.HTTPConflict: 409 CONFLICT: Response specification matching http status_code 409 not found for operation Operation(status). Either add a response specification for the status_code or use a 'default' response.
and the UI: SwaggerUIResponse
I have written AWS lambda in python to send message to sns topic.
I am using aws code pipeline to deploy this code in clould.
Running this lambda by calling api gateway.
python code is as below:
import boto3
from shared.environment import Env
from account.initiate_transition.transition_event_service import TransitionEventService
from shared.utils import Logger
from shared.xray_utils import trace
from shared.keep_warm import keep_warm
LOG = Logger.initialise_logger('transition-sms', None)
ENV = Env({Env.SMS_SNS_TOPIC_ARN, Env.AWS_REGION_NAME, Env.SMS_TRANSITION_TABLE})
SNS_CLIENT = boto3.client('sns')
DYNAMO_DB = boto3.resource('dynamodb', region_name=ENV.get(Env.AWS_REGION_NAME))
COGNITO_CLIENT = boto3.client('cognito-idp', region_name=ENV.get(Env.AWS_REGION_NAME))
SMS_TRANSITION_TABLE = DYNAMO_DB.Table(ENV.get(Env.SMS_TRANSITION_TABLE))
EVENT_SERVICE = TransitionEventService(SMS_TRANSITION_TABLE,
SNS_CLIENT,
ENV.get(Env.SMS_SNS_TOPIC_ARN),
COGNITO_CLIENT)
#trace
#keep_warm
def lambda_handler(event, context):
LOG = Logger.initialise_logger('transition-sms', context.aws_request_id)
try:
return EVENT_SERVICE.handle(event)
except Exception as e:
LOG.error(str(e))
transition_event_service.py
from account.initiate_transition.transition_sms_event import TransitionSmsEvent
from shared.utils import ApiGatewayResponse, Logger
from shared.xray_utils import trace
from http import HTTPStatus
from uuid import uuid4
from botocore.exceptions import ClientError
from jose import jwt
LOG = Logger.get_logger(__name__)
class TransitionEventService:
def __init__(self, sms_transition_table, sns_client, topic_arn, cognito_client):
LOG.debug('Initialising TransitionEventService')
self.sms_transition_table = sms_transition_table
self.sns_client = sns_client
self.topic_arn = topic_arn
self.cognito_client = cognito_client
#trace
def handle(self, event):
try:
event_object = self.instantiate_event(event)
except Exception as e:
LOG.error(e)
return ApiGatewayResponse.init(HTTPStatus.BAD_REQUEST, {
'error': 'Invalid request'
})
quid = str(uuid4())
LOG.info('quid {}'.format(quid))
LOG.debug('Storing SMS transition details')
self.sms_transition_table.put_item(Item={
'id_token': event_object.id_token,
'landing_page': event_object.landing_page,
'quid': quid
})
# Get phone number claim and verified claim
LOG.debug('Decoding id_token to get unverified claims')
claims = jwt.get_unverified_claims(event_object.id_token)
user_pool_id = claims['UserPoolId']
username = claims['Username']
url = "account/verify-transition?quid=123&&username=xyz"
response = self.cognito_client.admin_get_user(
UserPoolId = user_pool_id,
Username = username
)
phone_number = response['phone_number']
LOG.debug('Sending Transition SMS')
self.send_transition_sms(url=url, phone_number=phone_number)
LOG.debug('SMS sent to {}'.format(phone_number))
return ApiGatewayResponse.init(HTTPStatus.OK)
def instantiate_event(self, event):
return TransitionSmsEvent(event)
def send_transition_sms(self, url: str, phone_number: str):
try:
LOG.debug('Publishing SMS url to SNS Topic:{}'.format(self.topic_arn))
self.sns_client.publish(
TopicArn=self.topic_arn,
Message=json.dumps({
'default': json.dumps({
'url': url,
'phone_number': phone_number
})
}),
MessageStructure='json'
)
except ClientError as e:
LOG.error(e)
raise e
I getting below error in cloud watch logs:
Could someone help me resolving this issue.
If you have requirement.txt then please verify below entry should be present
python-jose-cryptodome==1.3.2
You have to import the library needed by your functions. To do that you have to create a virtual env and activate it:
virtualenv v-env
source v-env/bin/activate
Then you install your different libraries
pip install library1
pip install library2
...
And finally you desactivate the virtual environment and package your function :
deactivate
zip -r function.zip .
More infos : https://amzn.to/2oif6Wv
if you using requirement.txt you must include dependencies which required.
so once you run or deploy your code through code pipeline it will download the dependencies and zip into artifact which you can use through s3 for your python lambda.
once you call api gateway back up by python lambda it will not fail while importing.
no module named jose
It shows that you haven't specify dependency in your requirement.txt file.
depedency require for jose is
python-jose-cryptodome==1.3.*
Check whether python-jose-cryptodome==1.3.2 is added in your requirement.txt file.
If not add it this is major reason your getting this error.
I ran for awhile a python script to post articles on my blogspot blog.
everything ran smoothly until I started to get this auth error
RequestError: {'status': 401, 'body': 'User does not have permission to create new post', 'reason': 'Unauthorized'}
I really can't understand how to fix it reading gdata documentation.
Could you please suggest me how to do?
Thank you
Here the part of my code that doesn't work anymore:
from gdata import service
import gdata
import atom
blogger_service = service.GDataService('xxxxxx','xxxxxx')
blogger_service.service = 'blogger'
blogger_service.account_type = 'GOOGLE'
blogger_service.server = 'www.blogger.com'
blogger_service.ProgrammaticLogin()
def CreatePublicPost(blogger_service, blog_id, title, content,tags):
entry = gdata.GDataEntry()
entry.title = atom.Title('xhtml', title)
entry.content = atom.Content(content_type='html', text=content)
for tag in tags :
category = atom.Category(term=tag, scheme="http://www.blogger.com/atom/ns#")
entry.category.append(category)
return blogger_service.Post(entry, '/feeds/%s/posts/default' % blog_id)
Now there is a API version 3.0...
This old version is obsolete and no longer works, apparently...
You can find more about it here:
https://developers.google.com/blogger/
https://developers.google.com/blogger/docs/3.0/using/
And if you have questions about authentication, maybe those links help:
Having trouble trying to use gdata and oauth2 in python
Authentication with the Google Docs List API, Python and OAuth 2
I'm trying to create mail with py-appscript (AppleScript interface for python).
I tried following code,
from appscript import *
mail = app('Mail')
msg = mail.make(new=k.outgoing_message,
with_properties={'visible':True,
'content':"hello",
'subject':"appscript",
'sender':'taichino#gmail.com'
})
but got following error messages, and I couldn't find out any information for that...
CommandError: Command failed:
OSERROR: -1701
MESSAGE: Some parameter is missing for command.
COMMAND: app(u'/Applications/Mail.app').make('outgoing_message', with_properties={'content': 'hello', 'visible': True, 'sender': 'taichino#gmail.com', 'subject': 'appscript'})
Suggestions, please?
Problem solved by myself, following code works fine.
from appscript import *
mail = app('Mail')
msg = mail.make(new=k.outgoing_message)
msg.subject.set("hello"),
msg.content.set("appscript")
msg.to_recipients.end.make(
new=k.to_recipient,
with_properties={k.address: 'taichino#gmail.com'}
)
msg.send()
Insted of setting properties in constructor, set each property separately.