我正在尝试使用YouTube数据API在Python中搜索视频。我已经阅读了完整的教程,并且能够从本地计算机授权和认证用户,但是当我在服务器中部署相同的代码时,却在日志中看到下面列出的错误。并且浏览器显示“内部服务器错误”
[ N 2019-02-01 04:12:09.9860 4335/Tq age/Cor/CoreMain.cpp:1117 ]: Checking whether to disconnect long-running connections for process 20744, application /home/pricemon/YT_VDO_search_1 (production)
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 262, in parse_authorization_code_response
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 203, in parse_request_uri_response
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/requests_oauthlib/oauth2_session.py", line 208, in fetch_token
App 20744 output: File "/home/pricemon/YT_VDO_search_1/one.py", line 88, in oauth2callback
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
App 20744 output: File "/home/pricemon/virtualenv/YT__VDO__search__1/3.6/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
我正在尝试This guide from Google的男女同校
我已替换了Google API控制台中的重定向URL路径。
下面是我的代码。
def oauth2callback():
# Specify the state when creating the flow in the callback so that it can
# verified in the authorization server response.
state = flask.session['state']
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILE, scopes=SCOPES, state=state)
flow.redirect_uri = flask.url_for('oauth2callback', _external=True)
# Use the authorization server's response to fetch the OAuth 2.0 tokens.
authorization_response = flask.request.url
flow.fetch_token(authorization_response=authorization_response)
# Store credentials in the session.
# ACTION ITEM: In a production app, you likely want to save these
# credentials in a persistent database instead.
credentials = flow.credentials
flask.session['credentials'] = credentials_to_dict(credentials)
return flask.redirect(flask.url_for('test_api_request'))
使用命令flow.fetch_token
获取令牌时出现错误