The use of the square brackets is overloaded, as [consumer key] in Python indicates a list containing a variable with your consumer key, whereas the intention of the documentation is for the entire bit, square brackets too, to be replaced with a string.
The not-good outcome
The not-good outcome is that if a new user trying to use twitter-api for the first time accidentally puts ["AAAAAAAA"] instead of "AAAAAAAAAA" for their consumer/access token key/secret, they get a very cryptic error message that gives no indication of how to fix the problem:
<...very long traceback...>
~/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/oauthlib/oauth1/rfc5849/utils.py in escape(u)
55 if not isinstance(u, unicode_type):
56 raise ValueError('Only unicode objects are escapable. ' +
---> 57 'Got %r of type %s.' % (u, type(u)))
58 # Letters, digits, and the characters '_.-' are already treated as safe
59 # by urllib.quote(). We need to add '~' to fully support rfc5849.
ValueError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x111411518> of type <class 'generator'>.
The problem with the current documentation
On this page of the documentation (https://python-twitter.readthedocs.io/en/latest/getting_started.html#getting-your-application-tokens), the following bit of example code is given:
The use of the square brackets is overloaded, as
[consumer key]
in Python indicates a list containing a variable with your consumer key, whereas the intention of the documentation is for the entire bit, square brackets too, to be replaced with a string.The not-good outcome
The not-good outcome is that if a new user trying to use twitter-api for the first time accidentally puts
["AAAAAAAA"]
instead of"AAAAAAAAAA"
for their consumer/access token key/secret, they get a very cryptic error message that gives no indication of how to fix the problem:Proposed solution
I propose replacing this code example with:
or better yet include some code from one of the examples: https://github.com/bear/python-twitter/blob/master/examples/view_friends.py