facebook graph api使用python sdk为facebook获取访问令牌交换的代码

I am trying to get the code for login so that I can exchange the same for an access token .I tried using php by going to the redirect url and its working , I am unable to do the same using python .

My code I tried for getting the code

import facebook
import urllib2 as urllib
import requests

app_id='xxx'

app_secret='yyyyyyyyy'

redirect_uri='redirect_for_python_sdk.php'

scopes="public_profile, basic_info , read_friendlists, user_birthday,  user_likes, user_interests, user_education_history,  user_website, user_activities,user_groups,  user_photos,  user_friends"

dialog_url="http://www.facebook.com/dialog?client_id="+app_id+"&redirect_uri="+redirect_uri+"&granted_scopes="+scopes


a=urllib.urlopen(dialog_url)
print a.read()

Its not giving the output .I also tried what I did using php

print ("<script>top.location.href='" + dialog_url + "'</script>")

How should I go to the redirect_uri using python so that I can get the code and exchange the same for an access token? I also browsed through python sdk for facebook .The have implemented functions for getting app access token and exchange code for access token ,but how to get the code using python? please help ..