Comments (8)
Fwiw I've reached out to the GroupMe devs to see if we can get an updated attachments API doc
from groupy.
@brycecorbitt the fix is available on the PyPI in v0.10.3 👍
from groupy.
Hm, it should fall back to a generic attachment class if the type isn't one I've seen before (like "file"). Which version of groupy are you using?
from groupy.
Groupy version: 0.10.2
Python version: 3.6.7
OS: Ubuntu 18.04.1
from groupy.
I just tested out calling the gallery messages on a test chat. Similarly to my other chats it worked fine, but I got the same error as earlier after uploading a Microsoft Word document to it and running the same test again.
If it helps at all, I have the trace here:
File "/test.py", line 6, in <module>
gal = list(group.gallery.list_all())
File "/venv/lib/python3.6/site-packages/groupy/api/messages.py", line 453, in list_all
return self.list(**params).autopage()
File "/venv/lib/python3.6/site-packages/groupy/api/messages.py", line 441, in list
since=since, after=after, limit=limit)
File "/venv/lib/python3.6/site-packages/groupy/pagers.py", line 92, in __init__
super().__init__(manager, endpoint, **params)
File "/venv/lib/python3.6/site-packages/groupy/pagers.py", line 24, in __init__
self.items = self.fetch()
File "/venv/lib/python3.6/site-packages/groupy/pagers.py", line 42, in fetch
return self.endpoint(**self.params)
File "/venv/lib/python3.6/site-packages/groupy/api/messages.py", line 429, in _raw_list
return [Message(self, **message) for message in messages]
File "/venv/lib/python3.6/site-packages/groupy/api/messages.py", line 429, in <listcomp>
return [Message(self, **message) for message in messages]
File "/venv/lib/python3.6/site-packages/groupy/api/messages.py", line 298, in __init__
super().__init__(manager, conversation_id, **data)
File "/venv/lib/python3.6/site-packages/groupy/api/messages.py", line 269, in __init__
self.attachments = Attachment.from_bulk_data(attachments)
File "/venv/lib/python3.6/site-packages/groupy/api/attachments.py", line 55, in from_bulk_data
return [cls.from_data(**a) for a in attachments]
File "/venv/lib/python3.6/site-packages/groupy/api/attachments.py", line 55, in <listcomp>
return [cls.from_data(**a) for a in attachments]
File "/venv/lib/python3.6/site-packages/groupy/api/attachments.py", line 44, in from_data
return cls._types[type](**data)
TypeError: __init__() got an unexpected keyword argument 'file_id'
from groupy.
Hm... it's not clear what's causing the problem. The code path involved in that traceback seems to handle the stated problem case as expected:
>>> client = groupy.Client.from_token('uhuhah')
>>> att_data = [{'file_id': 'f411b36a-08a5-4ba5-a2aa-b3fb5a766599', 'type': 'file'}]
>>> attachment, = groupy.attachments.Attachment.from_bulk_data(att_data)
>>> attachment
<groupy.api.attachments.Attachment at 0x109ed0198>
>>> attachment.type
'file'
>>> attachment.file_id
'f411b36a-08a5-4ba5-a2aa-b3fb5a766599'
>>> attachment.data
{'file_id': 'f411b36a-08a5-4ba5-a2aa-b3fb5a766599', 'type': 'file'}
>>>
Looking at the attachments module, the error you see would be the result of a known attachment type (i.e. one of the Attachment
subclasses) with an unexpected field (file_id
in this case):
>>> att_data = [{'type': 'split', 'file_id': 'foo'}]
>>> attachment, = groupy.attachments.Attachment.from_bulk_data(att_data)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-a6a828e78b62> in <module>()
----> 1 attachment, = groupy.attachments.Attachment.from_bulk_data([{'type': 'split', 'file_id': 'foo'}])
~/code/Groupy/groupy/api/attachments.py in from_bulk_data(cls, attachments)
53 :rtype: :class:`list`
54 """
---> 55 return [cls.from_data(**a) for a in attachments]
56
57
~/code/Groupy/groupy/api/attachments.py in <listcomp>(.0)
53 :rtype: :class:`list`
54 """
---> 55 return [cls.from_data(**a) for a in attachments]
56
57
~/code/Groupy/groupy/api/attachments.py in from_data(cls, type, **data)
42 """
43 try:
---> 44 return cls._types[type](**data)
45 except KeyError:
46 return cls(type=type, **data)
TypeError: __init__() got an unexpected keyword argument 'file_id'
Does the group in question contain such an attachment?
from groupy.
Yes, and I think I figured out where it's happening. When _raw_list() is called in the Gallery class to fetch the messages from the gallery, the message with the document that is supposed to have the type 'file' has 'image' as its type instead but retains the 'file_id' parameter. Here's what the attachment looks like:
[{'file_id': 'b4d467fe-df42-4808-8bb8-b3158bfb8cd5', 'type': 'image', 'url': 'https://i.groupme.com/1000x1000.png.683fd319ce4143f48d257f4f19ef0a15'}]
The url it has seems to be some generic error image. The file_id
is different here than above because I'm using a test group.
To get the attachment information in my initial post, I used a messages call, which processes the attachment fine:
[{'file_id': 'b4d467fe-df42-4808-8bb8-b3158bfb8cd5', 'type': 'file'}]
Could this be an issue with the API?
from groupy.
Ah, I see! So the attachment data for files in the gallery are returned differently.
Unfortunately, the gallery endpoint isn't documented at all so we're really in uncharted territory here. It could very well be a bug in the API but I suspect this behavior may be expected by their chat frontends.
I think it's easy enough to handle this gracefully in the client so I'll push that out in a new version soon. I'll also press the devs for more docs on this stuff and just double check they're aware of this behavior.
Thanks for reporting this!
from groupy.
Related Issues (20)
- ApiError crashing the bot HOT 12
- attachments module: import errors, not serializable HOT 3
- Mentions not serializing on Post method HOT 6
- Mentions not serializing when posting from a Bot HOT 1
- API Key should not rely on global module-level variable HOT 17
- Recieve is spelled Receive
- Can't install even when Pillow is installed HOT 5
- authorization error.. anyone else? HOT 2
- Can't send messages to a chat? HOT 9
- potential parsing error on large groups HOT 2
- Like comments in a group without conversation_id? HOT 2
- Get 'likes' stats on a particular message HOT 2
- API Token Validation HOT 2
- Issue with groups containing emoji in group name HOT 2
- Can't create multiple bots with no callback url HOT 6
- Adding to a group with user-id
- Adding by user id issue HOT 1
- Issue retreiving current location attachment
- How to Reply to Messages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from groupy.