I am making a simple slack bot using github action:
But every time I tried to post a message to my channel, the error ocurrs
Traceback (most recent call last):
File "4_distributed_mlblogbot_to_py_update.py", line 130, in <module>
text = "{0} \n*{1}* \n<{2}|{3}> :bell:".format(today, bible1, 'https://sum.su.or.kr:8888/bible/today' , script) )
File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/slacker/__init__.py", line 515, in post_message
'mrkdwn': mrkdwn,
File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/slacker/__init__.py", line 126, in post
api, **kwargs
File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/slacker/__init__.py", line 102, in _request
raise Error(response.error)
slacker.Error: account_inactive
So everytime I try, I reinstall the app and invite my bot to mychannel
But It doesn't work
Meanwhile, In my personal python env(ex, colab) there are no errors.
Should I give up the token based BOT and get the webhook based bot?
Thank you
Every time I get a new auth(ex webhooks, tokens) and I run the github action, Always failed about the auth.
The hint was my "blabla.py" and the failed alarm email
I mistakenly expose my auth(IT SHOULD BE A SECRET) and Github and slack automatically drop my auth for security issue.
So after I used secret function in Github action, It works
Related
I'm trying to authenticate to SharePoint Online. Using sharepy v 2.0, pyCharm community edition, and python 3.9.
When I run:
'sharepy.connect('siteurl')'
From within PyCharm, Sharepy will freeze after I input my username in the run dialog box.
If I add the 'username' parameter and run it. Nothing happens. I'm never prompted for a password
If I use the console and enter in sharepy.connect('siteurl') then username and password (same goes for passing those parameters) I will get an error:
Traceback (most recent call last):
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 75, in _get_token
token = root.find('.//wsse:BinarySecurityToken', ns).text
AttributeError: 'NoneType' object has no attribute 'text'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\session.py", line 15, in connect
return SharePointSession(site, auth=autoauth)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\session.py", line 61, in __init__
self.auth.login(self.site)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 27, in login
self._get_token()
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 77, in _get_token
raise errors.AuthError('Token request failed. Invalid server response')
sharepy.errors.AuthError: Token request failed. Invalid server response
It should be noted I'm getting O365 from godaddy and the login page is federated? I think is the correct term.
According to the new release of Sharepy, this shouldn't matter.
Has anyone else had this freezing problem happen for them?
How would I authenticate with sharepoint using sharepy given my current situation?
The source of this problem ended up being GoDaddy. As we were federated using GoDaddy as the O365 provider. There was no way to authenticate correctly using sharepy.
The ultimate solution was to defederate away from GoDaddy (pretty easy to do thanks to this guy: Defederation Guide)
The reason we were unable to authenticate was because our provider redirects the login to their own login site. And unfortunately the sharepy builtin method of "auth" wouldn't work with GoDaddy.
I tested this theory before migrating away from GoDaddy. By using a fresh tenant. I also found that when you enable MFA the password/username method of authentication doesn't work.
NOTE: When new tenants are created they utilize a blanket security protocol which forces MFA. Even though MFA is shown as disabled in the Azure AD > Users section. To turn this off you must disable "Security Defaults": portal.azure.com > Azure Active Directory > Properties > "Manage security defaults" (at the bottom of the screen, its a small hyperlink).
A note on MFA and authentication with sharepy. There are methods to leave MFA enabled which work with other sharepoint/python things. I haven't tested them using sharepy yet, but will be turning on MFA and using one of the following methods:
App Password
Sharepoint API client secret
Azure App Registration (Azure App Reg)
I am trying to deploy this Telegram bot* on Heroku: https://github.com/radinshayanfar/TGCopyBot. The bot first needs to sign in to my account, which requires a login code that's sent to my devices on which I'm already logged in. When running the bot locally from a terminal, it requests input from the user, Enter code:, upon which I enter the login code in the terminal and press Enter, and the bot proceeds to do its work. But after deploying the bot on Heroku and running the dyno, it fails and this shows in the logs:
2021-06-26T12:55:33.312544+00:00 app[worker.1]: Enter code:Traceback (most recent call last):
2021-06-26T12:55:33.312546+00:00 app[worker.1]: File "/app/app/main.py", line 77, in <module>
2021-06-26T12:55:33.312729+00:00 app[worker.1]: tg.login()
2021-06-26T12:55:33.312730+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/telegram/client.py", line 493, in login
2021-06-26T12:55:33.312946+00:00 app[worker.1]: result = actions[authorization_state]()
2021-06-26T12:55:33.312948+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.9/site-packages/telegram/client.py", line 585, in _send_telegram_code
2021-06-26T12:55:33.313163+00:00 app[worker.1]: code = input('Enter code:')
2021-06-26T12:55:33.313168+00:00 app[worker.1]: EOFError: EOF when reading a line
2021-06-26T12:55:33.373308+00:00 heroku[worker.1]: Process exited with status 1
2021-06-26T12:55:33.427790+00:00 heroku[worker.1]: State changed from up to crashed
It may then automatically start the bot again, and proceed to crash and output the same errors as above. What's the problem here, and how can it be fixed?
If the issue is its request for the login code, then I do receive the login code on my other devices, but how do I give the login code to the bot? More generally, how do you repsond to a request for user input from any bot deployed on Heroku?
*not really a Telegram bot made with #BotFather; it just uses the Telegram API development tools
On your local environment, the built-in input works fine because you have access to the Terminal and can provide the input.
On Heroku there is no such an option so the command returns the EOFError exception because the function hits the end-of-file condition (EOF) without reading anything.
A possible solution might be to request the user to enter the login code via the Telegram Bot, for example as first step after the user starts chatting.
It seems the issue is with the request for user input, and that there is no direct way for the user to input anything on Heroku as they would on a terminal. The code can be modified to accept what would be inputted as an environment variable in this case, by using e.g. a session string: https://docs.pyrogram.org/topics/storage-engines#session-strings, https://docs.telethon.dev/en/latest/concepts/sessions.html#string-sessions
I'm maintaining a Python application using the official Dropbox API. To ask the users to let my application use their Dropbox account, I use a small script using the DropboxSession class, which is clearly the same as the one we can find on this blog post :
# Include the Dropbox SDK libraries
from dropbox import client, rest, session
# Get your app key and secret from the Dropbox developer website
APP_KEY = '******'
APP_SECRET = '******'
# ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
ACCESS_TYPE = 'app_folder'
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
request_token = sess.obtain_request_token()
url = sess.build_authorize_url(request_token)
# Make the user sign in and authorize this token
print "url:", url
print "Please visit this website and press the 'Allow' button, then hit 'Enter' here."
# Python 2/3 compatibility
try:
raw_input()
except NameError:
input()
# This will fail if the user didn't visit the above URL
access_token = sess.obtain_access_token(request_token)
#Print the token for future reference
print access_token
While it's perfectly working with Python 2.7.6, it seems to fail because of Dropbox code in Python 3.4 (the raw_input problem having been dealt with). I get this error :
Traceback (most recent call last):
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/session.py", line 285, in _parse_token
key = params['oauth_token'][0]
KeyError: 'oauth_token'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "get_access_token.py", line 12, in <module>
request_token = sess.obtain_request_token()
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/session.py", line 185, in obtain_request_token
self.request_token = self._parse_token(response.read())
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/session.py", line 287, in _parse_token
raise ValueError("'oauth_token' not found in OAuth request.")
ValueError: 'oauth_token' not found in OAuth request.
Long story short, after having studied the faulty code, it seems that the Dropbox code searches for a string dictionary key, despite the fact that in Python 3, those keys become bytestrings (i.e. it lookups 'oauth_token', which isn't here, instead of b'oauth_token', which is here).
However, even after having fixed the code to see if that's the only issue, no luck, I get another error further in the procedure:
Traceback (most recent call last):
File "get_access_token.py", line 25, in <module>
access_token = sess.obtain_access_token(request_token)
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/session.py", line 214, in obtain_access_token
response = self.rest_client.POST(url, headers=headers, params=params, raw_response=True)
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/rest.py", line 316, in POST
return cls.IMPL.POST(*n, **kw)
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/rest.py", line 254, in POST
post_params=params, headers=headers, raw_response=raw_response)
File "/home/scylardor/.virtualenvs/onitu3/lib/python3.4/site-packages/dropbox/rest.py", line 227, in request
raise ErrorResponse(r, r.read())
dropbox.rest.ErrorResponse: [401] 'Unauthorized'
So the faulty functions are sess.obtain_request_token() and sess.obtain_access_token(request_token). And the Python 2.7 version works fine, but I'd like to keep Python 3 compatibility.
So, does anyone know how one's supposed to make it work in Python 3 ? Could it be deliberately broken in order to make people move on to new procedures ? I could have sworn it was working with Python 3, some time ago.
Thank you for your time if you have an idea :)
edit: It seems the Dropbox SDK just isn't fully Python 3-compatible yet. So, I guess there's nothing else to do than to wait for them to update the SDK.
Try to use version 1.6
$ pip install dropbox==1.6
Better than waiting for the SDK to be compatible, you can use (or contribute to and use) the "community" fork, dropbox-py3 (here on github).
(Those quotes are big quotes. For now it's just me coding this, and just the part I need, but everyone's welcome to help. I think it's mainly identifying the few parts that are missing a ".encode" because it's mixing bytes and strings.)
Years back I built a simple mail form that has been working like a champ, but in the last couple months the logs show I'm getting an error when EmailMessage's send() method gets called.
I wrote a quick test to see if a stripped down version of an EmailMessage would work without error:
class TestEmail(webapp.RequestHandler):
def get(self):
fromAddress = "APPOWNEREMAIL#gmail.com"
email = mail.EmailMessage(sender=fromAddress)
email.to = self.request.get('to') + '#gmail.com'
email.subject = "Test Email"
email.body = "Testing the email system"
email.html = "<strong>Testing the <em>email</em> system</strong>"
email.check_initialized()
email.send()
Simple enough, but if I call that with:
http://MYAPPNAME.appspot.com/test-email?to=TOTALLYLEGITEMAIL
I still get the same error (note check_initialized() isn't throwing an error):
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
handler.get(*groups)
File "/base/data/home/apps/s~myappname/3.354527616249361817/myappname.py", line 370, in get
email.send()
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 895, in send
raise e
ApplicationError: ApplicationError: 1 Internal error
I haven't made any recent changes to the app, it's a lightly used app well below quota, it's sending as the email associated with the app owner and after spending a few hours scrutinizing the code, I'm still no closer to an answer.
Even more distressing, every Google search I come up with offers no new help. The best I could find was this question: Google app engine send mail service raises exception which sounds exactly like my problem, but in that case there wasn't a solution, the problem just went away.
Any idea how I can track this one down? Let me know if I need to clarify anything. Thanks!
What is your appid?
There is currently an issue that sending mail from an application whose appid is the same as the owner's gmail name will fail. eg, I have a gmail address "moishel at gmail dot com"; if I created an app whose appid is 'moishel' (before version 1.6.0) it will fail when trying to send mail. Note that this problem does not exist for apps created with version 1.6.0 or after.
Here's the issue: http://code.google.com/p/googleappengine/issues/detail?id=5320
I tried to run the example script of adwords_api_python, unfortunately met following erros:
[root#centos adwords_api_python_13.2.0]# python get_related_keywords.py
Traceback (most recent call last):
File "get_related_keywords.py", line 56, in <module>
page = targeting_idea_service.Get(selector)[0]
File "adspygoogle/adwords/TargetingIdeaService.py", line 79, in Get
'TargetingIdea', self._loc, request)
File "adspygoogle/adwords/AdWordsWebService.py", line 256, in CallMethod
self.__ManageSoap(buf, start_time, stop_time, error)
File "adspygoogle/adwords/AdWordsWebService.py", line 125, in __ManageSoap
raise e
adspygoogle.adwords.AdWordsErrors.AdWordsAuthenticationError: AuthenticationError.NOT_ADS_USER # ; trigger:'738513257043' Service[TargetingIdeaService.get]
I have applied a MCC account, and
applied the adowrds api token
(status: waiting for the examination
and approval).
I have run the "config.py" script
to set authentication headers.
Should i wait until they accept my application?
Yes, you need to wait until your application is approved. Then you will be able to find your developer token by logging into the MCC account and looking in the "API Center" section of the "My Account" tab.
It was taking up to two weeks to approve the token a few years back but it's usually much faster now.
The best thing to do is create a "Test Account" while your waiting for your MCC account to be approved. You don't have to wait for approval on a test account plus you're not developing against your production account;)