Python Google Voice - python

I am using the google voice API from here, and trying to send text messages from Python. However, whenever I try to log in using this code, I get something I do not expect:
from googlevoice import tests
from googlevoice import Voice
from googlevoice.util import input
def login():
username, password = "xyz#gmail.com", "******"
client = Voice.login(username, password)
return client
Upon starting this code's parent program (a file that literally just says run this sketch), I get this prompt:
Email Address:
If I enter an email address, it just freezes. Any help would be greatly appreciated.
I've read a few places that the Google Voice API support is coming to an end/has ended and am wondering if this is why I'm getting an error... If so, are there any free alternatives that are python compatible? I don't want to pay to have to text from my computer!

Somehow, this has made it work now:
from googlevoice import Voice
from googlevoice.util import input
import sys
import BeautifulSoup
import fileinput
import Listen #A voice recognition script I wrote
def login():
username, password = "xyz#gmail.com", "******"
voice = Voice()
client = voice.login(username, password)
return client
The only thing different that I've done is changed some of the libraries I've imported, but I can finally get past that "Email Address: " error, and run the rest of my code. have yet to try and test it my sending a text yet though!
#Merlin2011 and #jknupp17, thank you so much for your suggestions!

Related

"accounts.spotify.com sent an invalid response" Spotipy API

Coding on VScode and on Windows 11
Hi everybody. I was very excited when I discovered the potential of the Spotify's API. However I'm still struggling with the authentication step. I'm trying to connect to my own spotify account so far.
Bellow is the basic code I was trying to run:
`
import spotipy
import spotipy.util as util
my_username = "47tol*******************h7en8"
my_scope = "user-library-read"
token =util.prompt_for_user_token(username = my_username,
scope = my_scope,
client_id = "5e5197d3dd2c4a52bdad0bead149c334",
client_secret = "7t********************14",
redirect_uri = "http://797096755318371914146942828329574")
sp = spotipy.Spotify(auth = token)
user = sp.current_user()
print(user["display_name"])
print(user["followers"]["total"])
`
This kind of works and properly open the web browser (chrome) but the spotify logging page shows "accounts.spotify.com sent an invalid response"
enter image description here
I have tried everything but can't get by this issue.
Right before, on the same computer, I have run this code
`
import spotipy
from spotipy.oauth2 import SpotifyOAuth
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="5e5197d3dd2c4a52bdad0bead149c334",
client_secret="7t********************14",
redirect_uri="http://797096755318371914146942828329574",
scope="user-library-read"))
user = sp.current_user()
print(user['display_name'])
print(user['followers']['total'])
`
It opened the browser, I confirmed the connexion (my spotify account is connected on chrome), then the following code run smoothly.
I read maybe the connexion token has been saved on my computer so maybe I can't connect twice the same account to my App through the API??? Anyway I've tried :
`
os.remove(f".cache-{my_username}")
`
But it couldn't be able to find the file so I guess the problem is not that the token was already stored on my computer.
I then tried to run this code on another computer. The chrome page to connect to spotify opened well, I click on connect. Then the "accounts.spotify.com sent an invalid response" show up again and I'm back at the same point.
I you have some hint I'll be glad to read you. Many thanks
PS: The user name is mine. It is shown like this when on my spotify account (the one to listen to music) i click on "copy link to profile". I think it's because I create my account through a facebook account. I have also tried my "proper" spotify username but doesn't work neither.

Microsoft Bot Emulator showing "sending failed. Retry". VSCode shows KeyError: 'HTTP_CONTEXT_TYPE'

I am new to Microsoft Bot Framework, I am learning it through a youtube video https://youtu.be/ynG6Muox81o and making my bot on python3 on Ubuntu.
The Microsoft Bot Emulator says "sending failed. Retry".
Visual Studio Code shows KeyError: 'HTTP_CONTEXT_TYPE'.
I did everything right, my bot is connected to http://localhost:3978/, and bot emulator is connected to http://localhost:3978/api/messages/.
Many people on stackoverflow who had the same issue faced it due to windows firewall, but mine is ubuntu and i did check if it was enabled but its not.
app.py
from flask import Flask, request, Response
from botbuilder.schema import Activity
from botbuilder.core import BotFrameworkAdapter,BotFrameworkAdapterSettings
import asyncio
from echobot import EchoBot
app = Flask(__name__)
loop = asyncio.get_event_loop()
botadaptersettings=BotFrameworkAdapterSettings("","")
botadapter = BotFrameworkAdapter(botadaptersettings)
ebot = EchoBot()
#POST is the message
#app.route("/api/messages",methods=["POST"])
def messages():
#checking if HTTP file format is JSON or not
if "application/json" in request.headers["context-type"]:
#reading the JSON message
jsonmessage = request.json
else:
#unsupported media type 415
return Response(status=415)
activity = Activity().deserialize(jsonmessage)
async def turn_call(turn_context):
await ebot.on_turn(turn_context)
task = loop.create_task(botadapter.process_activity(activity,"",turn_call))
loop.run_until_complete(task)
if __name__ == '__main__':
app.run('localhost',3978)
echobot.py
from botbuilder.core import TurnContext
class EchoBot:
async def on_turn(self,turn_context:TurnContext):
await turn_context.send_activity(turn_context.activity.text)
I cant seem to understand the issue and how to fix it. it would be really helpfull if someone could help me fix this as i am really interested in building bots.
I have uploaded my Bot Project on gitlab https://gitlab.com/pdmnbhrawal/myechobot01.
This is a simple typo. You've written "context-type" instead of "content-type." The YouTube tutorial you linked to tells you to write a line like this:
if "application/json" in request.headers["content-type"]:
In order to avoid this kind of typo, you can download the source code that the video links to directly instead of trying to rewrite it yourself.
You can troubleshoot this kind of error yourself by noticing in the stack trace that it tells you what line of code is throwing the error. When it says KeyError: 'HTTP_CONTEXT_TYPE' that should indicate to you that you've entered the wrong key and you should check for a typo. You can also try using a debugger and stepping through your code.
There are a few other problems with the bot that you may notice. It doesn't handle conversation update activities correctly because it doesn't account for the incoming activity having no text. It also doesn't return an HTTP response from the api/messages endpoint. You might want to fix those problems later, but your bot will run despite them.

How can I log in to my Facebook from python program without getting locked?

I am trying to send messages to Facebook friends via Messenger. I found a tutorial & tried it.
import fbchat
from getpass import getpass
username = str(raw_input("Username: "))
client = fbchat.Client(username, getpass())
no_of_friends = int(raw_input("Number of friends: "))
for i in xrange(no_of_friends):
name = str(raw_input("Name: "))
friends = client.getUsers(name) # return a list of names
friend = friends[0]
msg = str(raw_input("Message: "))
sent = client.send(friend.uid, msg)
if sent:
print("Message sent successfully!")
When I ran the program, it requested me my password. And, of course, I entered it. But Facebook doesn't accept the request from my program & lock my Facebook account. I think this is due to security reasons. Then how can I log in to my Facebook from python program without getting locked? Thanks.
This seems like the issue lies with your library, not with you. You should make a new issue at their github page. https://github.com/carpedm20/fbchat
You can selenium to remotely control the browser and do stuff a normal user can do, including logging into facebook.

Why the client.listen in fbchat cannot work again?

I wan to make a chatbot that will automatically reply . it will collect reply from client.listen and then decide the reply to the user.
from fbchat import log, Client
# Subclass fbchat.Client and override required methods
class EchoBot(Client):
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
self.markAsDelivered(thread_id, message_object.uid)
self.markAsRead(thread_id)
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))
# If you're not the author, echo
if author_id != self.uid:
self.send(message_object, thread_id=thread_id, thread_type=thread_type)
client = EchoBot("myaccount", "mypassword")
client.listen()
It worked fine until today.
Even it receive the message.the program still will stuck in client.listen
The output that i receive is this
Logging in myAccount...
Login of myAccount successful.
Listening...
When i try to contact my account , it still wont give me reply but it just stuck in client.listen
the output i wan to get is it will collect info from client.listen() and give me reply.
I believe that facebook has changed the structure of the website (id's, classes...) where fbchat library was scraping data from (Keep in mind that fbchat is not an official facebook library). This can happen with any API that is not official. I have hosted my bot 24/7 and all of sudden it stopped working. Your code is perfectly correct. From what I have tested so far I can tell that EchoBot class stopped working with all of it's event listeners, but at the other hand you can still send messages with client.send(...) We can only hope that developers of fbchat library will fix this soon.
See here for more info: https://github.com/carpedm20/fbchat/issues/483
2020 UPDATE
The issue was fixed in new version of fbchat 1.9.6.
Just update the module with:
pip install fbchat --upgrade

Python: How to "asterisk out" / hide a password whilst typing it on screen?

Auth_url isn't defined here but in the longer version it is and successfully logs in. The issue is, the input box that appears does not "asterisk out" the password. Is there a simple way to correct this issue? Thanks
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
from suds.sax.element import Element
import getpass
user = "my username"
pw = getpass.getpass("Password: ")
auth_client = Client(auth_url)
cookie = auth_client.service.authenticate(user, pw)
the issue is with Pyscripter. If you run the code in cmd or convert it to .exe, it should work correctly.

Categories