API call return 404 error
greyli opened this issue · comments
When I call github.get('/user')
in my code, I got GitHubError: 404: Not Found
.
Here is the code, the authorization part is good.
@auth.route('/login/github')
def github_login():
return github.authorize(scope="user")
@github.access_token_getter
def token_getter():
if current_user.is_authenticated:
return current_user.access_token
@auth.route('/callback/github')
@github.authorized_handler
def authorized(access_token):
next_url = request.args.get('next') or url_for('chat.app')
if access_token is None:
return redirect(next_url)
user = User.query.filter_by(access_token=access_token).first()
if user is None:
user = User(access_token=access_token)
user.save()
login_user(user)
github_user = github.get('/user') # the error line
print github_user
return redirect(url_for('chat.profile'))
user.access_token = access_token
user.save()
login_user(user)
return redirect(next_url)
The API endpoint is listed in here.
Did I do something wrong? Any help will be appreciated.
I finally figure it out. GitHub-Flask support two kinds of endpoint: one for complete URL, such as https://api.github.com/user
, another is endpoint without leading slash, such as user
.
I think it's better to support pattern like /user
, because this patterns were commonly used in GitHub's API documentation.