执行dev_appserver.py时,我收到以下错误:
from google.auth import app_engine
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/ python/runtime/sandbox.py"
, line 1147, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named google.auth
奇怪的是,当我部署应用程序时,它运行正常。
我试过了:
其他信息:
以下是SDK版本:
文件:
的app.yaml
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
libraries:
- name: flask
version: 0.12
- name: six
version: "1.9.0"
appengine_config.py
from google.appengine.ext import vendor
import os
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)),'lib'))
main.py
import logging
from flask import Flask
from sheets import data
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!{}'.format(data)
@app.errorhandler(500)
def server_error(e):
# Log the error and stacktrace.
logging.exception('An error occurred during a request.')
return 'An internal error occurred.', 500
sheets.py
from google.auth import app_engine
import googleapiclient.discovery
SCOPES = ['https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/spreadsheets.readonly',
'https://www.googleapis.com/auth/sqlservice.admin']
spreadsheetId = '<spreadsheet-id>'
rangeName = 'A1:A5'
credentials = app_engine.Credentials(scopes=SCOPES)
service = googleapiclient.discovery.build('sheets', 'v4', credentials=credentials)
data = service.spreadsheets().values().get(spreadsheetId=spreadsheetId,
range=rangeName).execute()
data = data.get('values',[])
/ lib中
.
..
apiclient
cachetools
cachetools-2.0.1.dist-info
google
googleapiclient
google_api_python_client-1.5.2.dist-info
google_api_python_client-1.6.5.dist-info
google_auth-1.4.1.dist-info
google_auth-1.4.1-py3.6-nspkg.pth
google_auth_httplib2-0.0.3.dist-info
google_auth_httplib2.py
google_auth_httplib2.pyc
httplib2
httplib2-0.10.3.dist-info
oauth2client
oauth2client-2.2.0.dist-info
oauth2client-4.1.2.dist-info
pyasn1
pyasn1-0.4.2.dist-info
pyasn1_modules
pyasn1_modules-0.2.1.dist-info
rsa
rsa-3.4.2.dist-info
simplejson
simplejson-3.13.2.dist-info
six-1.11.0.dist-info
six.py
six.pyc
uritemplate
uritemplate-0.6.dist-info
uritemplate-3.0.0.dist-info
我解决了这个问题:
dev_appserver.py没有使用我的lib文件夹中的模块。相反,它使用我的计算机上的包。为了解决这个问题,我从本地计算机中删除了所有Google软件包,现在它运行良好。
答案 0 :(得分:2)
https://github.com/GoogleCloudPlatform/google-auth-library-python/issues/169#issuecomment-315417916
我通过以上评论解决了这个问题:
是的,我在appengine_config.py中有以下内容:
from google.appengine.ext import vendor
vendor.add('lib')
我设法通过使用以下代码来解决模块加载问题:
import os
import google
from google.appengine.ext import vendor
lib_directory = os.path.dirname(__file__) + '/lib'
# Change where to find the google package (point to the lib/ directory)
google.__path__ = [os.path.join(lib_directory, 'google')] + google.__path__
# Add any libraries install in the "lib" folder.
vendor.add(lib_directory)
答案 1 :(得分:0)
我在from google.auth.crypt import base
中很有可能遇到了问题,并且已经解决了,因此您可以尝试一下。
转到存在导入问题的文件,然后手动更改:
from google.auth import app_engine
到:
import app_engine