I am using tweepy (a python lib for twitter api) to create a twitter app. Below is the django view code where I am creating an OAuthHandler with consumer key,secret and getting request token and saving it in django.messages and redirecting it to the authorization url.
Later during the callback view I am retrieving the request token and creating an OAUthHandler, but I getting this below error on ‘auth.get_access_token(v)’
TweepError at /twitter/return/
argument 2 to map() must support iteration
Traceback :
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/nzee/Downloads/uday/homepage/../homepage/users/views.py" in tw_return
80. auth.get_access_token(v)
File "/usr/local/lib/python2.6/dist-packages/tweepy-1.9-py2.6.egg/tweepy/auth.py" in get_access_token
126. raise TweepError(e)
Exception Type: TweepError at /twitter/return/ Exception Value:
argument 2 to map() must support iteration
Views.py code below
def tw_return(request):
v = request.GET.get('oauth_verifier')
key = settings.TWITTER_KEY
secret = settings.TWITTER_SECRET
auth = tweepy.OAuthHandler(key, secret)
mess = get_messages(request)
a=[]
for m in mess:
a.append(m)
auth.set_request_token(a[0],a[1])
auth.get_access_token(v)
api = tweepy.API(auth)
api.update_status('tweepy + oauth1!')
return HttpResponseRedirect('/')
def twitter(request):
key = settings.TWITTER_KEY
secret = settings.TWITTER_SECRET
auth = tweepy.OAuthHandler(key, secret)
try:
redirect_url = auth.get_authorization_url()
except tweepy.TweepError:
raise Http404
messages.add_message(request, messages.INFO, auth.request_token.key)
messages.add_message(request, messages.INFO, auth.request_token.secret)
return HttpResponseRedirect(redirect_url)
wrong:
I suspect that you are not receiving an oauth_verifier, so it’s value isNone(i.e., not an iterable)this question may help: Tweepy twitter oauth authentication not returning oauth_verifier
Here’s an example of an appEngine handler that uses tweepy, maybe it’ll help?
https://github.com/sclm/tweepy-examples/blob/master/appengine/oauth_example/handlers.py
Final Answer:
I think you are not getting the correct request token from get_messages()… the error you are getting occurs if you call
auth.set_request_token()withNone. Found this in the issues on github for tweepy https://github.com/tweepy/tweepy/issues/25