python-twitter
python-twitter copied to clipboard
CreateListsMember returning error code 112 when hyphen in slug string
When trying to add to a list named "Voices Social Isolation" I received the following error
twitter.error.TwitterError: [{'code': 112, 'message': 'You must specify either a list ID or a slug and owner.'}]
I'm definitely explicitly specifying both:
api.CreateListsMember(slug=list_to_post,screen_name=user,
owner_screen_name=list_owner)
I changed the name of the list to "TestList" and it went through fine. Looking at the source code, this is an issue with lists that have spaces in the name. Not sure what the fix would be though.
The problem here is confusion because of inconsistency between the list name as it is presented to a user and how that list name is encoded by twitter internally (i.e. the slug) As an example, per the twitter api documentation "A list’s name must start with a letter and can consist only of 25 or fewer letters, numbers, “-”, or “_” characters." Yet, it is possible when using the twitter web client to create a list with spaces in the name. Doing so, however, will create a list whose name as displayed for the user is different than its name as referenced by the api.
Examples (four new lists created sequentially using the web client):
| Name Presented by the User | Slug generated by API | Note |
|---|---|---|
| thisIsAList | thisisalist | All lowercase characters |
| this is A List | this-is-a-list | All lowercase, hyphens replace spaces |
| this is a list | this-is-a-list1 | conflicts with previous slug, 1 appended |
| this-is-a-list1 | this-is-a-list11 | conflicts with previous slug, 1 appended |
In order to avoid this error (code 112) when making an api call it is necessary to use the correct internal slug and not the name of the list as presented (or created by) the user.
api.CreateListsMember(slug="voices-social-isolation", screen_name="KyloR3n", owner_screen_name="JCLacivita") works just fine for a twitter list presented to a user as "Voices Social Isolation."
wow, thank you @jamielacivita !