Communal Blocklist Day 2
Prelude: Received David’s very nice response addressing my github issue: https://github.com/singingwolfboy/flask-dance/issues/1#issuecomment-59752587
There’s a fix coming! And a suggestion for upgrading to an unreleased version for request-oauthlib for now.
8:50 PM: Changed requirements.txt to use git+https://github.com/requests/requests-oauthlib.git@23fc41b#egg=requests_oauthlib
Also, had to run this pip command: pip install git+https://github.com/requests/requests-oauthlib.git@23fc41b#egg=requests_oauthlib –upgrade
The –upgrade is important here.
8:53 PM: New Error! This is a win! Sort of.
TokenRequestDenied: Token request failed with code 401
Desktop applications only support the oauth_callback value ‘oob’
Time to Google that.
8:59 PM: Something about needing a callback_url. And I tried to put localhost:5000 in my settings. Doesn’t work. https://twittercommunity.com/t/why-cant-i-use-localhost-as-my-oauth-callback/708
9:08 PM: Cool. Just put in a placeholder in Twitter App settings, and it worked. New Error!
RuntimeError: the session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
9:21 PM: So I set the secret key as a configuration of the Flask App, which in my localhost/heroku case looks like this.
app.config['SECRET_KEY’] = os.environ['SECRET_KEY’]
And I have to set the secret key remotely using “$ heroku config:set SECRET_KEY=XXXXXXXX” plus locally in my .env file.
9:24 PM: New Error! The code where I am getting things back from Twitter!
resp = twitter.get(“/account/verify_credentials”)
assert resp.ok
Gives the following in the logs.
File “/Users/tony_chu/Documents/communal-blocklist/main.py”, line 23, in index
assert resp.ok
AssertionError
This is good - it means it got through the other stuff. Now how do I log things in Python?
9:55 PM: Ok, so after a bunch of fangling, it looks like I got OAuth to work, but twitter.get(“/account/verify_credentials”) is wonky?
Regardless, I got some other endpoints to work, most notably:
resp = twitter.get(“blocks/list.json”)
app.logger.debug(dir(resp))
assert resp.okreturn resp.content
So now I can see my own blocklist. In browsing the API docs, I discovered that in twitter, blocking and muting are two different concepts.
10:17 PM: Code worked … locally. So tried to deploy to Heroku. Turns out that I wrote the requirements.txt update wrong. Instead of:
psycopg2==2.5.4
requests==2.4.3
requests_oauthlib==git+https://github.com/requests/requests-oauthlib.git@23fc41b#egg=requests_oauthlib
It should be:
psycopg2==2.5.4
requests==2.4.3
-e git+https://github.com/requests/requests-oauthlib.git@23fc41b#egg=requests_oauthlib
I just don’t know pip syntax.
… but something else is still wrong.
10:24 PM: So my redirect URL was static and set to 127.0.01 - making that yet another environment variable worked.

Wooohoo! Calling it a night.