Twilio - Python : NameError from Udacity Tutorial - python

Hoping I could get input on what this error means and what I have to do to fix it. Thanks.
This is the error that appears:
Traceback (most recent call last):
File "/Users/davidongchoco/Desktop/Python Programming/send_text.py", line 11, in <module>
from_="+13348331130") # Replace with your Twilio number
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/sms_messages.py", line 167, in create
return self.create_instance(kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 365, in create_instance
data=transform_params(body))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 200, in request
resp = make_twilio_request(method, uri, auth=self.auth, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 164, in make_twilio_request
uri=resp.url, msg=message, code=code)
TwilioRestException:
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m
[36m[49mPOST https://api.twilio.com/2010-04-01/Accounts/ACf37c4004688accd3f501ab2a2c9dc7e1/SMS/Messages.json[0m
[37m[49mTwilio returned the following information:[0m
[34m[49mPermission to send an SMS has not been enabled for the region indicated by the 'To' number: +639228902063.[0m
[37m[49mMore information may be available here:[0m
[34m[49mhttps://www.twilio.com/docs/errors/21408[0m
>>>

Twilio developer evangelist here.
The error has delivered a message to you that says:
Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +639228902063.
More information may be available here:
https://www.twilio.com/docs/errors/21408
If you follow that link, it tells you that you need to enable some global permissions on your account. You can do that here: https://www.twilio.com/user/account/settings/international/sms
It looks as though you are trying to send to a number from the Philippines, so make sure that check box is ticked.
Good luck with the Udacity course!

Related

My telegram userbot can forward a message in private but not in a supergroup

I am writing a small project related to userbots in telegram. I had a problem when trying to forward a message from a supergroup to another user, but when I try to forward messages from a regular chat, everything is successful. I found a similar question, but unfortunately bots are used there, not userbots.
Lib: pyrogram
Version: 1.4.8
my code:
#app.on_message(filters.group & filters.text)
async def formessage(client, message):
text = message.text.lower()
# other code
await message.forward(botdata["id"])
I also tried using the function: app.forward_messages(botdata["id"], message.chat.id, message.message_id)
but alas, I get the same error
The error that I get when a new message in the supergroup:
Traceback (most recent call last):
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 121, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 147, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: 5279709634'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\dispatcher.py", line 222, in handler_worker
await handler.callback(self.client, *args)
File "C:\Users\nyansterowo\Desktop\tg\src\UserBot.py", line 43, in formessage
await message.forward(botdata["id"])
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\types\messages_and_media\message.py", line 2924, in forward
return await self._client.forward_messages(
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\messages\forward_messages.py", line 83, in forward_messages
to_peer=await self.resolve_peer(chat_id),
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 123, in resolve_peer
raise PeerIdInvalid
pyrogram.errors.exceptions.bad_request_400.PeerIdInvalid: Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it
Let me remind you once again that I am writing a selfie and not a bot. I can easily forward a message from the group to someone through the telegram client itself, but I can’t do it through the code.
Firstly, the error you get is clear. The Session of your userbot has not yet met the group and cannot identify it based on its ID. You will have to receive any kind of update from that entity first.
See this FAQ entry: https://docs.pyrogram.org/faq/peer-id-invalid-error
Secondly, the group you are trying to forward from may have forwards restricted in its group settings. Since you can forward via an official client, this is likely not the case.

AUTHENTICATIONFAILED - LOGIN Invalid credentials

I´m trying to connect my python-scrip with Thunderbird. Thunderbird uses my yahoo-mail.
With following code I should be able to connect to Thunderbird:
M = imaplib.IMAP4_SSL(config.server)
M.login(config.user, config.passwd)
M.select("inbox")
but I have the following issue:
Loaded classifier and label encoder with tag 'productive'
Traceback (most recent call last):
File "main.py", line 51, in <module>
M.login(config.user, config.passwd)
File
"C:\AppData\Local\Continuum\ anaconda3\envs\nn_dev\lib\imaplib.py", line
593, in login
raise self.error(dat[-1])
imaplib.error: b'[AUTHENTICATIONFAILED] LOGIN Invalid credentials'
How can I solve this problem?
If you can connect to Yahoo with Thunderbird, you should be able to connect directly to Yahoo with Python: just use the same login data you used in Thunderbird.
Otherwise, maybe there is some type of block on the Yahoo side (for example, if you activated two-step authentication)

Instagram API access token generation throws "You must provide a client_id" error even though I provided one

Generating an access token for the Python Instagram API requires running this file and then entering a Client ID, Client Secret, Redirect URI, and Scope. The console then outputs a URL to follow to authorize the app and asks for the code generated afterwards. Theoretically after this process it should return an access token.
Instead, it's throwing an error:
Traceback (most recent call last):
File "get_access_token.py", line 40, in <module>
access_token = api.exchange_code_for_access_token(code)
File "C:\Users\Daniel Leybzon\Anaconda2\lib\site-packages\instagram\oauth2.py", line 48, in exchange_code_for_access_token
return req.exchange_for_access_token(code=code)
File "C:\Users\Daniel Leybzon\Anaconda2\lib\site-packages\instagram\oauth2.py", line 115, in exchange_for_access_token
raise OAuth2AuthExchangeError(parsed_content.get("error_message", ""))
instagram.oauth2.OAuth2AuthExchangeError: You must provide a client_id
Screenshot provided for context:

getUser return EDAMSystemException errorCode=8

I'm trying to get my account information by evernote api on python, however, I got errors :
Traceback (most recent call last): File "", line 1, in
File "build/bdist.linux-x86_64/egg/evernote/api/client.py", line 148, in delegate_method
File "build/bdist.linux-x86_64/egg/evernote/edam/userstore/UserStore.py", line 1033, in getUser
File "build/bdist.linux-x86_64/egg/evernote/edam/userstore/UserStore.py", line 1058, in recv_getUser
evernote.edam.error.ttypes.EDAMSystemException: EDAMSystemException(errorCode=8, rateLimitDuration=None, _message='authenticationToken')
My python code as below:
from evernote.api.client import EvernoteClient
dev_token="my develop token"
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()
user = userStore.getUser()
I'm sure I've generated a valid developer token for my Evernote account, as shown in the picture, I have a develop token in my account link
Is there anything I missed?
By the way, I use the code above and replace the key with another develop token generated by Evernote sandbox account, it's ok.
If you are not on sandbox, try:
client = EvernoteClient(token=dev_token, sandbox=False)

gdata internal error

Since yesterday a working Python gdata program has stopped working after I changed the IP address used.
I receive the following stack trace:
Traceback (most recent call last):
File "C:\prod\googleSite\googleSite2.py", line 23, in
feed = client.GetContentFeed()
File "C:\Python27\lib\site-packages\gdata\sites\client.py", line 155, in get_c
ontent_feed
auth_token=auth_token, **kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 635, in get_feed
**kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 320, in request
RequestError)
gdata.client.RequestError: Server responded with: 500, Internal Error
The code is as follow:
import gdata.sites.client
import gdata.sites.data
client = gdata.sites.client.SitesClient(source='xxx', site='yyy')
client.ssl = True # Force API requests through HTTPS
client.ClientLogin('user#googlemail.com', 'password', client.source);
feed = client.GetContentFeed();
Update:
The issue fixes itself after an hour - is there any kind of commit or logout to avoid this?
Since you're not passing anything in GetContentFeed, it's using CONTENT_FEED_TEMPLATE % (self.domain, self.site) as the URI. I'm not sure if the IP change had an impact on what the self.domain/self.site values should be, but it might be worth checking those out.

Categories