내가 requirements.txt 구성을 잘못하여 사건을 재현 할 수있다 [1] :
여기 내 로그인 코드입니다. 이 샘플 [2]에서 큰 쿼리에 대한 테스트를 시작하고 범위를 수정했습니다. 여기서 ClientId와 ClientSecret은 json 파일에 있습니다. 그 json의 내용을 [3]에서 얻을 수 있습니다. OAuth 자격 증명을 만들고 json 콘텐츠를 client_secret.json에 복사해야합니다.
샘플에서는 appengine 응용 프로그램의 종속성을 나열하는 requirements.txt를 볼 수 있습니다. 샘플이 동일한 경로에서 로컬 lib 폴더에있는 모든 종속성을 설치 살고 폴더 내에서 다음 명령을 실행 을 -r requirements.txt -t lib 디렉토리/
내 requirements.txt의 모습 설치 PIP :
를
google-api-python-client==1.6.4
google-auth==1.2.0
google-auth-httplib2==0.0.2
그런 다음 해당 lib/폴더에서 프로젝트의 종속성을 찾을 수 있습니다. main.py 습관이있는 프로그램의 루트에는 appengine_config.py라는 파일이 있습니다.이 파일은 lib 폴더를 GAE 응용 프로그램에로드하고 Python 프로그램에서 해당 라이브러리를 가져올 수 있도록합니다.
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
는 또한, 당신은 당신의 클라이언트 ID와 clientSecret에 대한 내용을 배치하는 데 필요한 client_secrets.json이있다 : 같은 appengine_config.py 보인다.
bigquery 샘플과 동일한 가져 오기로 앱을 배포하면 제대로 작동해야합니다.
gcloud app deploy
여기 수정 코드를 공유합니다. 희망이 도움이 :
import json
import os
import googleapiclient.discovery
from oauth2client.contrib.appengine import
OAuth2DecoratorFromClientSecrets
import webapp2
# The project id whose datasets you'd like to list
PROJECTID = 'Your-project-id'
# Create the method decorator for oauth.
decorator = OAuth2DecoratorFromClientSecrets(os.path.join(os.path.dirname(__file__), 'client_secrets.json'),scope='https://www.googleapis.com/auth/bigquery')
#decorator = OAuth2DecoratorFromClientSecrets(os.path.join(os.path.dirname(__file__), 'client_secrets.json'),scope='https://www.googleapis.com/auth/plus.login')
# Create the bigquery api client
service = googleapiclient.discovery.build('bigquery', 'v2')
class MainPage(webapp2.RequestHandler):
# oauth_required ensures that the user goes through the OAuth2
# authorization flow before reaching this handler.
@decorator.oauth_required
def get(self):
# This is an httplib2.Http instance that is signed with the user's
# credentials. This allows you to access the BigQuery API on behalf
# of the user.
http = decorator.http()
response = service.datasets().list(projectId=PROJECTID).execute(http)
self.response.out.write('<h3>Datasets.list raw response:</h3>')
self.response.out.write('<pre>%s</pre>' % json.dumps(response, sort_keys=True, indent=4,separators=(',', ': ')))
class MainAware(webapp2.RequestHandler):
# credentials. This allows you to access the BigQuery API on behalf
# oauth_required ensures that the user goes through the OAuth2
# authorization flow before reaching this handler.
@decorator.oauth_aware
def get(self):
# This is an httplib2.Http instance that is signed with the user's
# credentials. This allows you to access the BigQuery API on behalf
# of the user.
if decorator.has_credentials():
http = decorator.http()
response = service.datasets().list(projectId=PROJECTID).execute(http)
self.response.out.write('<h3>Datasets.list raw response:</h3>')
self.response.out.write('<pre>%s</pre>' % json.dumps(response, sort_keys=True, indent=4,separators=(',', ': ')))
else:
url = decorator.authorize_url()
# Write a page explaining why authorization is needed,
# and provide the user with a link to the url to proceed.
# When the user authorizes, they get redirected back to this path,
# and has_credentials() returns True.
self.response.out.write(url)
app = webapp2.WSGIApplication([
('/', MainPage),
('/aware', MainAware),
# Create the endpoint to receive oauth flow callbacks
(decorator.callback_path, decorator.callback_handler())
], debug=True)
# [END all]
[1] https://cloud.google.com/appengine/docs/standard/python/getting-started/python-standard-env#setting_up_libraries_to_enable_development
[2] https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/bigquery
[3] https://console.cloud.google.com/apis/credentials?project=your-project-id
난 그냥 가지고 생각 httplib2, 충분하지 여기 봐 가지고 HTTPS ://pypi.python.org/pypi/google-auth-httplib2 –
가져 오기를 시도해보십시오. 'import google_auth_httplib2' –