Executing the script show that the error happens on verifier = request.GET.get('oauth_verifier')
, and googling for the error message shows this error is related to Flask.
So I guess Flask just doesn’t like using request.GET.get
outside a function called by Flask (which could be what they call a “request context”).
Basically, you should execute the last line only somewhere it makes sense to display data (a web server can only display data if there is a web browser waiting for a response…)