泊坞窗:谷歌表最小的例子错误

我有一个烧瓶的应用程序,从谷歌表中提取一些数据。 当我在本地机器上运行烧瓶应用程序时,最初它是通过0auth2validation创build证书并将其存储在本地。 在本地应用程序成功完成之后,我在Docker容器中创build了相同的应用程序。

情况1
该容器具有在创build容器时复制/添加的凭证。 在这种情况下,烧瓶应用程序没有任何问题

情景2
该容器目前没有凭证文件。 所以,它必须通过调用get_credentials()函数来生成文件。 此时,网页浏览器停留在等待服务器的响应(浏览器处于加载阶段)

情况2是问题。 希望可以有人帮帮我 ..
我正在关注这个文档 。
Dockerfile

 FROM python:2.7-slim WORKDIR g_api ADD . /g_api RUN pip install -r requirements.txt EXPOSE 8000 

泊坞窗,compose.yml

 version: "3" services: web: build: context: . dockerfile: Dockerfile command: "python g_api.py" ports: - "8000:8000" networks: - webnet volumes: - .:/g_api networks: webnet: 

requirements.txt

 flask==0.12.2 google-api-python-client==1.6.2 

g_api.py

 from __future__ import print_function from flask import Flask import httplib2 import os from apiclient import discovery from oauth2client import client from oauth2client import tools from oauth2client.file import Storage app = Flask(__name__) try: import argparse flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() except ImportError: flags = None SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly' CLIENT_SECRET_FILE = 'client_secret.json' APPLICATION_NAME = 'Google Sheets API Python Quickstart' def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ credential_dir = os.path.join(os.getcwd(), 'credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'sheets.googleapis.com-python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials @app.route('/') def main(): """Shows basic usage of the Sheets API. Creates a Sheets API service object and prints the names and majors of students in a sample spreadsheet: https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit """ credentials = get_credentials() http = credentials.authorize(httplib2.Http()) discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?' 'version=v4') service = discovery.build('sheets', 'v4', http=http, discoveryServiceUrl=discoveryUrl) spreadsheetId = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms' rangeName = 'Class Data!A2:E' result = service.spreadsheets().values().get( spreadsheetId=spreadsheetId, range=rangeName).execute() values = result.get('values', []) if not values: return "Not Success" # print('No data found.') else: print('Name, Major:') for row in values: # Print columns A and E, which correspond to indices 0 and 4. print('%s, %s' % (row[0], row[4])) return "Success" if __name__ == '__main__': app.run(host='0.0.0.0', port=int(8000), debug=True) 

directory_sructure

 .g_api ├── client_secret.json ├── credentials ├── docker-compose.yml ├── Dockerfile ├── g_api.py └── requirements.txt 

编辑

容器日志 (docker日志cont_id)

 WARNING: Error loading config file:/home/jpg/.docker/config.json - stat /home/jpg/.docker/config.json: permission denied * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 200-757-358 /usr/local/lib/python2.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access /g_api/credentials/sheets.googleapis.com-python-quickstart.json: No such file or directory warnings.warn(_MISSING_FILE_MESSAGE.format(filename)) * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 200-757-358