python-telegram-bot AttributeError: 'CallbackContext' object has no attribute 'left_chat_member' - telegram

I do not know English, so I am writing to you with google translate. Sorry if I use the wrong word.
What I want to do with this code is to detect the member who left my telegram group and to ban automatically.
But I am getting such an error. Can you help me with this? Thanks.
from telegram.ext import MessageHandler, Filters
import telegram
with open("token.txt","r") as f:
TOKEN = f.read()
def start(update,source):
update.message.reply_text("Merhaba")
def handle_left_member(bot, update):
left_user = update.left_chat_member
bot.kickChatMember(chat_id=update.message.chat_id, user_id=left_user.id)
update = telegram.ext.Updater(TOKEN,use_context=True)
disp = update.dispatcher
disp.add_handler(telegram.ext.CommandHandler("start",start))
left_member_handler = MessageHandler(Filters.status_update.left_chat_member, handle_left_member)
disp.add_handler(left_member_handler)
update.start_polling()
update.idle()
The error I encountered is as follows.
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\dispatcher.py", line 557, in process_update
handler.handle_update(update, self, check, context)
File "C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\handler.py", line 199, in handle_update
return self.callback(update, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\username\Desktop\TelegramBot\den.py", line 11, in handle_left_member
left_user = update.left_chat_member
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CallbackContext' object has no attribute 'left_chat_member'

You have installed a version of python-telegram-bot between 12.0 and 13.15 but your handle_left_member function is written for version <=11, as it takes the arguments bot and update instead of update and context. Please see the transition guide of v12 for details.
Please note that neither of these versions are maintained anymore, only the new version v20.x is mainained.
To upgrade your code to v20, please read the release notes and the transition guide.
Disclaimer: I'm currently the maintainer of python-telgeram-bot.

Related

cuxfilter.dashboard.DashBoard.preview keeps throwing "NameError: name 'launch' is not defined" at me

TLDR:
await d.preview() # throws "NameError: name 'launch' is not defined"
# d.preview() # does not throw "NameError: name 'launch' is not defined"; however, it still does not produce the desired image in a jupyter notebook... It's __repr__ prints <coroutine object DashBoard.preview at 0x7f44013aaa70>`
I'm trying to preview a rapids dashboard that is correctly rendering in a separate browser window. However, when I try to preview a rasterized screengrab of the dashboard using the convenient looking plotly method, d.preview(), I keep getting this paradoxical exception, "NameError: name 'launch' is not defined".
await d.preview() works in the documentation here:
https://docs.rapids.ai/api/cuxfilter/stable/themes/Themes.html
I am running rapids21.08 in python3.7 on ubuntu (Pop!_OS 20.10) using an RTX2080 GPU using a jupyter notebook with the default jupyter theme made using $ jt -r, and I am not using any matplotlib funny business. I have run the very common import matplotlib.pyplot as plt command.
This seems like a really common problem which I'm surprised isn't just working... Maybe there's something obvious I'm just missing... Please help me!
The full exception can be found postscript.
Thank you for your time,
Tim
P.S.
# d = some cuxfilter.dashboard.DashBoard instance that apparently works with d.show()
await d.preview() # throws NameError: name 'launch' is not defined
throws
NameError: name 'launch' is not defined
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipykernel_8654/2723113380.py in async-def-wrapper()
~/anaconda3/envs/pyenv_ub/lib/python3.7/site-packages/cuxfilter/dashboard.py in preview(self)
507 port=port, websocket_origin=url, show=False, start=True
508 )
--> 509 await screengrab("http://" + url)
510 self.stop()
511
~/anaconda3/envs/pyenv_ub/lib/python3.7/site-packages/cuxfilter/assets/screengrab.py in screengrab(url)
6
7 async def screengrab(url):
----> 8 browser = await launch({"slowMo": 5}, args=["--no-sandbox"])
9 page = await browser.newPage()
10 await page.setViewport(
NameError: name 'launch' is not defined
This is probably due to the missing pyppeteer package. Installing this in the conda env should resolve the issue:
conda install -c conda-forge pyppeteer>=0.2.6
cuxfilter=21.10 won't have this issue, as the dependency has been added to it.

Error when exporting from BigQuery to MySQL

I am trying to export a table from BigQuery to Google Cloud MySQL database.
I found this operator called BigQueryToMySqlOperator (documented here https://airflow.apache.org/docs/apache-airflow-providers-google/stable/_api/airflow/providers/google/cloud/transfers/bigquery_to_mysql/index.html?highlight=bigquerytomysqloperator#module-airflow.providers.google.cloud.transfers.bigquery_to_mysql)
When I deploy the DAG containing this task onto cloud composer, the task always failed with the error
Traceback (most recent call last):
File "/opt/python3.8/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1113, in _run_raw_task
self._prepare_and_execute_task_with_callbacks(context, task)
File "/opt/python3.8/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1287, in _prepare_and_execute_task_with_callbacks
result = self._execute_task(context, task_copy)
File "/opt/python3.8/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1317, in _execute_task
result = task_copy.execute(context=context)
File "/opt/python3.8/lib/python3.8/site-packages/airflow/providers/google/cloud/transfers/bigquery_to_mysql.py", line 166, in execute
for rows in self._bq_get_data():
File "/opt/python3.8/lib/python3.8/site-packages/airflow/providers/google/cloud/transfers/bigquery_to_mysql.py", line 138, in _bq_get_data
response = cursor.get_tabledata(
File "/opt/python3.8/lib/python3.8/site-packages/airflow/providers/google/cloud/hooks/bigquery.py", line 2508, in get_tabledata
return self.hook.get_tabledata(*args, **kwargs)
File "/opt/python3.8/lib/python3.8/site-packages/airflow/providers/google/cloud/hooks/bigquery.py", line 1284, in get_tabledata
rows = self.list_rows(dataset_id, table_id, max_results, selected_fields, page_token, start_index)
File "/opt/python3.8/lib/python3.8/site-packages/airflow/providers/google/common/hooks/base_google.py", line 412, in inner_wrapper
raise AirflowException(
airflow.exceptions.AirflowException: You must use keyword arguments in this methods rather than positional
I don't really understand why it is throwing out this error. Can anyone help me figuring out what went wrong or how should I export data from BigQuery to MySQL DB? Much thanks for your help!
EDIT: My operator code would basically look like this
transfer_data = BigQueryToMySqlOperator(
task_id='task_id',
dataset_table='origin_bq_table',
mysql_table='dest_table_name',
replace=True,
)
Based on the stacktrace, you are most likely using apache-airflow-providers-google==2.2.0.
airflow.exceptions.AirflowException: You must use keyword arguments in
this methods rather than positional
This error originates from the GoogleBaseHook, which can be traced back the BigQueryToMySqlOperator.
BigQueryToMySqlOperator > BigQueryHook > BigQueryConnection > BigQueryCursor > get_tabledata
The reason why you are getting the AirflowException is because get_tabledata
is called as part of the execute method.
Unforuntately, the test for the operator is not comprehensive since it only checks whether or not the method was called was the correct parameters.
I think this will require a new release of the google provider where the cursor in BigQueryToMySqlOperator calls list_rows with keyword arguments instead of get_tabledata, which calls list_rows with positional arguments.
I have also made a Github Issue in the Airflow repository.

pyOptSparse Error: Received an unknown option (AMIEGO)

I recently came across AMIEGO. When I try to run the example problems (provided in the example directory) I get the following error.
-------------------------------------------------------------------------------
Exit Flag: True
Elapsed Time: 0.04829263687133789
======================ContinuousOptimization-End=======================================
+------------------------------------------------------------------------------+
| pyOptSparse Error: Received an unknown option: 'Major optimality tolerance' |
+------------------------------------------------------------------------------+
Traceback (most recent call last):
File "/home/sky/anaconda3/lib/python3.8/site-packages/openmdao/utils/concurrent.py", line 65, in concurrent_eval_lb
retval = func(*args)
File "/home/sky/anaconda3/lib/python3.8/site-packages/amiego/kriging.py", line 239, in _calculate_thetas
opt_x, opt_f, success, msg = snopt_opt(_calcll, x0, low, high, title='kriging',
File "/home/sky/anaconda3/lib/python3.8/site-packages/amiego/optimize_function.py", line 76, in snopt_opt
opt.setOption(name, value)
File "/home/sky/anaconda3/lib/python3.8/site-packages/pyoptsparse/pyOpt_optimizer.py", line 829, in setOption
raise Error("Received an unknown option: %s" % repr(name))
pyoptsparse.pyOpt_error.Error
I tested pyoptsparse optimization driver with the sellar problem and it worked as expected. So I think I'm missing something in AMIEGO. And fyi I didn't modify anything in the example, so I am running it with SLSQP(from pyoptsparse driver) for the continuous part(I dont have SNOPT). Any pointers on how to fix this or where to start looking will be helpful.
I've pushed up a couple of fixes to the repository so that you can run it without SNOPT. The basic Branin problem in the examples works and gets to the expected answer now. I can't promise that SLSQP is the best choice for more complicated problems as we usually favor SNOPT over SLSQP in our work. This is still very experimental code, so the documentation is weak and there are still a lot of control knobs and flags that are buried as subcomponent attributes (including ideas that we tried that didn't pan out). But we appreciate users who are willing to try AMIEGO and help us improve it.

Weird AttributeError: OpenMDAO says param has not been initialized when I run my simulation under mpirun

I am running developmental scientific code. I am stuck on a cryptic error message, and am curious what the OpenMDAO team thinks. When I run the code in serial, it works with no issues. When I run it under mpirun, OpenMDAO throws a cryptic error message:
Traceback (most recent call last):
File "test/exampleOptimizationAEP.py", line 129, in <module>
prob['ratedPower'] = ratedPower
.....
File "/scratch/jquick/test/lib/python2.7/site-packages/openmdao-1.7.3-py2.7.egg/openmdao/core/vec_wrapper.py", line 1316, in __setitem__
(self.name, name))
AttributeError: 'params' has not been initialized, setup() must be called before 'ratedPower' can be accessed
I am not sure how to approach this. There is nothing obviously different about the ratedPower variable in the code. What information does this error give me about what is going wrong?
This is a bug in OpenMDAO <= v1.7.2. Look at the output of check_setup and see the list of parameters without associated unknowns. You will find that variable in there. When running in parallel (because of the bug), you can not set any hanging params (ones without associated unknowns) in your setup script.
The way to fix it is to add an IndepVarComp to any variable you need to initialize the value of.

products.sqlalchemypas-1.0-py2.6.egg AttributeError: getGroupsForPrincipal

I am using products.sqlalchemypas-1.0-py2.6.egg for authenticating user from MSSQL Table. Authentication work as expected but now I'm trying implementaing groups plugin to
get groups from different table. What happening is when I'm trying to loggin its giving me error saying AttributeError: getGroupsForPrincipal.
Error Traceback is ..
2012-02-21T15:33:14 INFO Zope Ready to handle requests
2012-02-21T15:39:25 ERROR Zope.SiteErrorLog 1329838765.580.598770330561 http://localhost:8060/dev/login_form
Traceback (innermost last):
Module ZPublisher.Publish, line 115, in publish
Module ZPublisher.BaseRequest, line 596, in traverse
Module Products.PluggableAuthService.PluggableAuthService, line 235, in validate
Module Products.PluggableAuthService.PluggableAuthService, line 735, in _findUser
Module Products.PluggableAuthService.PluggableAuthService, line 668, in _getGroupsForPrincipal
AttributeError: getGroupsForPrincipal
My defination in plugin.py is ...
def getGroupsForPrincipal(self, principal=getSecurityManager().getUser().getId(),request=None):
"Getting groups from SIMS"
import pdb; pdb.set_trace()
groups = []
results = self.simsGroupForUser(username=principal)
for row in results.dictionaries():
group = row.get('group')
groups.append(group)
return groups
Don't know why its not able to reach this method in plugin.py however there is implatemented block where I did define this interface to implement resulting showing groups interface in my acl_user pas object.
[added]
I've tried to import my plugin in debugger and tried to reach this method and have same error so I dont know Do I need to define anything specifically to pick this method in my pas. I did define in my implements class to impelement IGroupsPlugin.
Any comment is great help as always.
I don't think you method definition does what you expect it to. principal=getSecurityManager().getUser().getId() will calculate the default parameter at import time rather than at method execution time.
Just found that My file has wrong indentation, that why it was giving attributes error. Thanks all for your time and comments.

Resources