rhgrant10 / groupy Goto Github PK
View Code? Open in Web Editor NEWA simple yet powerful API wrapper for the GroupMe messaging service.
Home Page: https://groupy.readthedocs.io
License: Apache License 2.0
A simple yet powerful API wrapper for the GroupMe messaging service.
Home Page: https://groupy.readthedocs.io
License: Apache License 2.0
The Endpoint
class docs say there are restrictions on arguments when retrieving messages, and so does the GroupMe API. However, there is no conditional to catch bad arguments - not in Endpoint
and not in Recipient
either. One or both of these methods should probably raise a ValueError if multiple arguments are supplied.
Hi,
first of all thanks for the project :)
I just started playing with it, and my first small test was trying to post with a bot.
It didn't work at first, since i got the error:
File "<snip>/groupy/object/responses.py", line 556, in post
endpoint.Bot.post(self.bot_id, text, picture_url)
AttributeError: 'module' object has no attribute 'Bot'
Exploring api/endpoints.py confirmed there isn't any reference to Bot, but i found Bots, which i substituted to Bot in line responses.py:556 and was able to post :)
I didn't correct it because i'm not sure if it was just luck to make it work (and also because i never really did a push on github and was afraid to mess something up), but i thought about letting you know
Thanks so much for developing the Python groupyAPI! The below issue is using GroupyAPI version 58 on Windows 7 with Python 3.4
I'm attempting to post messages using the bots.post call but i'm getting an exception return as shown below.
File "C:\Python34\lib\site-packages\groupy\object\responses.py", line 557, in
post
except errors.InvalidResponse as e:
AttributeError: 'module' object has no attribute 'InvalidResponse'
The message will post to the group but the script dies after that. Any advice on debugging this? I've tried digging into responses.py but not quite sure i'm good enough at python to help. Thanks for your time.
sorry i understand this is for issues and not support. i installed the latest today but i seem to be getting 401 auth errors from the api.
`[ec2-user@ip-172-31-22-33 groupme]$ python36 g.py
received a bad response
Traceback (most recent call last):
File "/usr/local/lib64/python3.6/site-packages/groupy/session.py", line 28, in request
response.raise_for_status()
File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 840, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.groupme.com/v3/users/me
Traceback (most recent call last):
File "/usr/local/lib64/python3.6/site-packages/groupy/session.py", line 28, in request
response.raise_for_status()
File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 840, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.groupme.com/v3/users/me
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "g.py", line 7, in
print (client.user.get_me())
File "/usr/local/lib64/python3.6/site-packages/groupy/api/user.py", line 27, in get_me
response = self.session.get(url)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib64/python3.6/site-packages/groupy/session.py", line 32, in request
raise exceptions.BadResponse(response) from e
groupy.exceptions.BadResponse: HTTP 401: unauthorized
`
the scrip is very simple to start:
`from groupy.client import Client
key = 'token_from_groupme'
client = Client.from_token(key)
for group in client.groups.list():
print (group.name)`
It appears that there's an issue when adding users to a group by user_id. This seems to be repeatable, even when using just raw posts/gets outside of this module, so it may be an issue on GroupMe's end
Add Alex to a new group by user_ID does not work (no exceptions, I read the result from the post and it returns forbidden)
Add Alex to a new group by their email works
Remove Alex from that group and nuke that group
Add Alex to a new group by the same user_ID as before works
Add Emily to a new group by user_ID does not work
I've confirmed that Emily's userID comes from the exact same place as Alex's does
It seems GroupMe only let's me interact with a user through their email or phone number when adding them to a group! Help!
I was using the following code to retrieve all of the gallery messages from a chat:
gallery = list(group.messages.list_all())
Which works fine for all of my groups except for one, that ends up throwing:
__init__() got an unexpected keyword argument 'file_id'
I tracked it down to this one message whose attachment is likely tripping it up:
'attachments': [{'file_id': 'f411b36a-08a5-4ba5-a2aa-b3fb5a766599', 'type': 'file'}]
It turned out to be an excel spreadsheet in my case, but my guess is that it'll also throw this error for the other document formats Groupme supports as well that share the type "file".
I'm trying to send attachments following the details here but I'm running into problems. I haven't run into any other issues with Groupy on my machine, running 32 bit python 3.5.2 through Conda on Windows 10.
>>> from groupy.attachment import Location
ImportError: No module named 'groupy.attachment'
>>> from groupy import attachment
ImportError: cannot import name 'attachment'
>>> from groupy import attachments # needs an s
>>> loc = attachments.Location.create('My house', lat=33, lng=-84)
AttributeError: type object 'Location' has no attribute 'create'
>>> from groupy import Group
>>> loc = attachments.Location('My house', lat=33, lng=-84)
>>> group = Group.list().filter(group_id=group_id)[0]
>>> group.post('test') # this works
True
>>> group.post('test', loc) # this doesn't
TypeError: Location(name='My house', lat=33, lng=-84) is not JSON serializable
I'm hosting my bot on Heroku, which is also throwing the same errors. Any help would be appreciated. Thanks for writing this great API wrapper.
I created a mention as documented with the id/loci info, but when calling post(text, mentionObj), I get a "TyperError about Mentions(['123456']) is not JSON serializable". I have no problems posting regular text to the group. Am I using the attachments.Mentions object wrong?
It appears that there's an issue when adding users to a group by user_id. This seems to be repeatable, even when using just raw posts/gets outside of this module, so it may be an issue on GroupMe's end
Add Alex to a new group by user_ID does not work (no exceptions, I read the result from the post and it returns forbidden)
Add Alex to a new group by their email works
Remove Alex from that group and nuke that group
Add Alex to a new group by the same user_ID as before works
Add Emily to a new group by user_ID does not work
I've confirmed that Emily's userID comes from the exact same place as Alex's does
It seems GroupMe only let's me interact with a user through their email or phone number when adding them to a group! Help!
Trying to run the example code on the documentation,
for group in client.groups.list_all():
print(group.name)
throws a groupy.exceptions.InvalidJsonError
. However, when I run this instead:
for group in client.groups.list(omit="membership").autopage():
print(group.name)
it runs successfully. This leads me to think that large user counts cause the JSON parsing to fail. I am in quite a few large groups (1800+, 700+, multiple 100+) which I think may be causing the issue.
The documentation recommends "[checking] that your API token is correct just before you use it to create a Groupy client." Should token validation become a part of a Groupy client's construction? The client could, for instance, attempt to read the user's profile and raise an UnauthorizedError
if the server returns a 401. The client would only be created if the token passes this validation check.
So I am making a bot using your API wrapper and I tried using a try except to deal with the groupy.api.errors.ApiError but it still gets through and crashes the bot. Any way to deal with this?
While downloading all the messages in a group via messages.iolder()
, when it hits the end of the group and GroupMe returns the expected 304 response, this ultimately triggers a fatal TypeError.
My current workaround is to catch and ignore those TypeErrors, but that's not quite optimal.
Here's some demonstration code similar to what's in the documentation:
#!/usr/bin/env python
# Test the messages.iolder() method which gives me these sorts of errors:
# File "/home/groupme/lib/python3.5/site-packages/groupy/object/responses.py", line 129, in messages
# if e.args[0]['code'] == status.NOT_MODIFIED:
# TypeError: 'Response' object is not subscriptable
from groupy import Group
group = Group.list().first
print("Messages in group: %s" % (group.message_count))
messages = group.messages()
while messages.iolder():
print("Messages downloaded: %s" % len(messages))
When run, the above eventually produces this traceback:
Traceback (most recent call last):
File "/home/groupme/lib/python3.5/site-packages/groupy/api/endpoint.py", line 69, in response
data = r.json()
File "/home/groupme/lib/python3.5/site-packages/requests/models.py", line 763, in json
return json.loads(self.text, **kwargs)
File "/home/groupme/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/home/groupme/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/groupme/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/groupme/lib/python3.5/site-packages/groupy/object/responses.py", line 126, in messages
since_id=since, after_id=after)
File "/home/groupme/lib/python3.5/site-packages/groupy/api/endpoint.py", line 303, in index
return cls.response(r)
File "/home/groupme/lib/python3.5/site-packages/groupy/api/endpoint.py", line 71, in response
raise errors.ApiError(r)
groupy.api.errors.ApiError: <Response [304]>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_iolder.py", line 13, in <module>
while messages.iolder():
File "/home/groupme/lib/python3.5/site-packages/groupy/object/listers.py", line 168, in iolder
old = self.older()
File "/home/groupme/lib/python3.5/site-packages/groupy/object/listers.py", line 145, in older
return self.group.messages(before=self.oldest.id)
File "/home/groupme/lib/python3.5/site-packages/groupy/object/responses.py", line 131, in messages
if e.args[0]['code'] == status.NOT_MODIFIED:
TypeError: 'Response' object is not subscriptable
The problem seems to be that "e" is of type ApiError and doesn't appear to have a 'code' index available.
It used to be 450 but now it has been increased to 1000.
This was working for me a few weeks ago. My code is the following (shaved down for brevity):
`
self._client = Client.from_token(token)
self._bots_manager = Bots(self._client.session)
self._bots_manager.create('My-Bot', self._group.group_id) # group ID has been verified
`
Exception(s) caught:
`
received a bad response
Traceback (most recent call last):
File "/groupy/session.py", line 28, in request
response.raise_for_status()
File "/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.groupme.com/v3/bots
Traceback (most recent call last):
File "/groupy/session.py", line 28, in request
response.raise_for_status()
File "/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.groupme.com/v3/bots
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "myproj.py", line 25, in
bot = MyBot()
File "myproj.py", line 16, in init
self._initialize_bot()
File "myproj.py", line 20, in _initialize_bot
self._bot = self._groupme.get_bot('My-Bot')
File "/src/groupme.py", line 58, in get_bot
self._bots_manager.create(name, self._group.group_id)
File "/groupy/api/bots.py", line 42, in create
response = self.session.post(self.url, json=payload)
File "/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/groupy/session.py", line 32, in request
raise exceptions.BadResponse(response) from e
groupy.exceptions.BadResponse: HTTP 400: Callback url callback url already registered for group
`
I read through the docs and didn't see anything like this, but is there any way to get things like the number of likes and which user IDs liked a message once I have a Message object?
Hi, while playing around with the library, I get the following stack trace
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/groupy/api/endpoint.py", line 56, in response
data = r.json()
File "/usr/local/lib/python3.4/site-packages/requests/models.py", line 763, in json
return json.loads(self.text, **kwargs)
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 2 (char 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/groupy/object/responses.py", line 222, in destroy
endpoint.Groups.destroy(self.group_id)
File "/usr/local/lib/python3.4/site-packages/groupy/api/endpoint.py", line 176, in destroy
return cls.response(r)
File "/usr/local/lib/python3.4/site-packages/groupy/api/endpoint.py", line 58, in response
raise errors.ApiError(r)
groupy.api.errors.ApiError: <Response [200]>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/mihirjoshi/PycharmProjects/pyGroupMe/AppModel.py", line 60, in <module>
main()
File "/Users/mihirjoshi/PycharmProjects/pyGroupMe/AppModel.py", line 56, in main
group.destroy()
File "/usr/local/lib/python3.4/site-packages/groupy/object/responses.py", line 223, in destroy
except errors.ApiErrorError as e:
AttributeError: 'module' object has no attribute 'ApiErrorError'
when trying to remove a group with the following code:
Group.create("test group")
sleep(10) # Just a delay so I can check groupme.com to make sure group was made
for group in Group.list().filter(name__contains='test'):
group.destroy()
I'm a novice to Python so I may have done something wrong, but the group is successfully deleted. I just get that exception raised for some reason.
Hi, I am able to post messages to a group using this library, but I wasn't able to find a way to reply to other members' messages. Would you please let me know if this feature is supported?
I tried to follow the tutorial that uses messages.iolder() within a while loop, and I get the following error. Any idea what I might be doing wrong?
>>> while messages.iolder():
... pass
...
Traceback (most recent call last):
File "/Users/dvmorris/Documents/Groupy/groupy/api/endpoint.py", line 69, in response
data = r.json()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/models.py", line 808, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/dvmorris/Documents/Groupy/groupy/object/responses.py", line 126, in messages
since_id=since, after_id=after)
File "/Users/dvmorris/Documents/Groupy/groupy/api/endpoint.py", line 303, in index
return cls.response(r)
File "/Users/dvmorris/Documents/Groupy/groupy/api/endpoint.py", line 71, in response
raise errors.ApiError(r)
groupy.api.errors.ApiError: <Response [304]>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dvmorris/Documents/Groupy/groupy/object/listers.py", line 168, in iolder
old = self.older()
File "/Users/dvmorris/Documents/Groupy/groupy/object/listers.py", line 145, in older
return self.group.messages(before=self.oldest.id)
File "/Users/dvmorris/Documents/Groupy/groupy/object/responses.py", line 129, in messages
if e.args[0]['code'] == status.NOT_MODIFIED:
TypeError: 'Response' object is not subscriptable
The removal of members is not working.
I am guessing from the stacktrace you ran into:
membership_id required
string โ Please note that this isn't the same as the user ID. In the members key in the group JSON, this is the id value, not the user_id.
>>> k.remove(k.members()[6])
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/groupy/object/responses.py", line 272, in remove
endpoint.Members.remove(self.id, member.user_id)
File "/usr/local/lib/python3.4/dist-packages/groupy/api/endpoint.py", line 226, in remove
return cls.response(r)
File "/usr/local/lib/python3.4/dist-packages/groupy/api/endpoint.py", line 59, in response
raise errors.ApiError(data['meta'])
groupy.api.errors.ApiError: {'errors': ['The requested path does not exist'], 'code': 404}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/groupy/object/responses.py", line 273, in remove
except errors.InvalidResponse as e:
AttributeError: 'module' object has no attribute 'InvalidResponse'
>>> k.remove(groupy.User.get())
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/groupy/object/responses.py", line 272, in remove
endpoint.Members.remove(self.id, member.user_id)
File "/usr/local/lib/python3.4/dist-packages/groupy/api/endpoint.py", line 226, in remove
return cls.response(r)
File "/usr/local/lib/python3.4/dist-packages/groupy/api/endpoint.py", line 59, in response
raise errors.ApiError(data['meta'])
groupy.api.errors.ApiError: {'errors': ['The requested path does not exist'], 'code': 404}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/groupy/object/responses.py", line 273, in remove
except errors.InvalidResponse as e:
AttributeError: 'module' object has no attribute 'InvalidResponse'
I am able to create a group successfully using groupy.Group.create. However, even when share is set to True, the Group created is not shareable. Consequentially, the new group's share_url is None. I am able to set it manually in the app and retrieve the share_url. I've looked through the Groupy code and there doesn't seem to be anything wrong with the API request. This may be a problem on GroupMe's end.
I can't installed it even when pillow is already installed
c:\users\igal\appdata\local\programs\python\python36\python.exe -u -c "import setuptools, tokenize;file='C:\Users\igal\AppData\Local\Temp\pip-build-l7ov0265\Pillow\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\igal\AppData\Local\Temp\pip-rraf97nf-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\igal\AppData\Local\Temp\pip-build-l7ov0265\Pillow\
I do not think the API supports liking a message in a group chat as it requires conversation_id which does not exists for group chats, only for direct messages.
Any help? I could be wrong.
Sending messages to a group chat works fine like so:
from groupy.client import Client
client = Client.from_token(TOKEN)
for c in client.groups.list_all():
chat = c
break
message = chat.post(text="Hello, world!")
But when I try to send a message to a chat, it does not:
for c in client.chats.list_all():
chat = c
break
message = chat.post(text="Hello, world!")
received a bad response
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/groupy/session.py", line 28, in request
response.raise_for_status()
File "/usr/lib/python3.6/site-packages/requests/models.py", line 840, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://api.groupme.com/v3/direct_messages
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/groupy/session.py", line 28, in request
response.raise_for_status()
File "/usr/lib/python3.6/site-packages/requests/models.py", line 840, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://api.groupme.com/v3/direct_messages
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/groupy/api/chats.py", line 63, in post
return self.messages.create(text=text, attachments=attachments)
File "/usr/lib/python3.6/site-packages/groupy/api/messages.py", line 242, in create
response = self.session.post(self.url, json=payload)
File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 511, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/lib/python3.6/site-packages/groupy/session.py", line 32, in request
raise exceptions.BadResponse(response) from e
groupy.exceptions.BadResponse: Got a bad response
So the primary error seems to be: Too Many Requests for url: https://api.groupme.com/v3/direct_messages
coming from the Requests library. I thought maybe this was because the Requests user-agent string was being rejected by the groupme website from too much abuse. I went into the Requests library and had it return a valid user-agent string by changing the default_user_agent
function in /usr/lib/python3.6/site-packages/requests/utils.py
. This didn't work unfortunately.
Anyone else have any idea why this might be happening?
Great library! Thanks for making it.
One issue is that if you want to build an app that allows users to provide their own API keys you can run into some thread safety issues by relying on the global config.API_KEY
param for all API requests. In the worst case this could result in users seeing data they should not have had access to!
It would be great if there was a way to specify the API to use for any individual request to workaround this issue.
If you agree this would be a good change, I might be able to take a crack at implementing it.
message = group.messages().newest
print(message.text) #printout is @user
print(message.text == "@user") #false
print(message.text is "@user") #false
Hopefully this library is still under development.
I'm trying to compare the contents of a message to a string. No matter what I try, the output is false. Any idea on how I should compare?
Hey, I'm an owner of a bot project named Ultros, a project that largely uses Twisted internally for all kinds of stuff. Naturally, Twisted hasn't yet been ported to Python 3, so I was wondering what the changes of a backport of Groupy to Python 2 are.
I noticed that this was a TODO, but I wanted to ask if there was any more info on this.
When running
for group in client.groups.list_all():
print(group.name)
threw a groupy.exceptions.InvalidJsonError: The JSON was incomplete/invalid
Upon leaving all groups with emoji in the group name, the code runs as intended.
Python Version: 3.7.3
Groupy Version: 0.10.3
OS: Windows 10, Version 10.0.17134
For "current location" the data comes back as:
{
"name": "Current Location"
}
Which yields the result:
could not create 'location' attachment: __init__() missing 2 required positional arguments: 'lat' and 'lng'
Would be nice to support this better.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.