本文介绍了App Engine未在dev_appserver.py中找到google.auth文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行dev_appserver.py时,我收到以下错误:

  from google.auth import app_engine 
在load_module
中输入
,1147行$ b $ Import ImportError('/ google / google-cloud-sdk / platform / google_appengine / google / appengine / tools / devappserver2 / python /没有名为%s'%fullname的模块)
ImportError:没有名为google.auth的模块

奇怪的是,当我部署应用程序,它工作正常。



我试过:


  1. dev_appserver.py MY_DIRECTORY

  2. cd / google / google-cloud-sdk / bin /; python dev_appserver.py MY_DIRECTORY

  3. python dev_appserver.py hello_world /

  4. 安装更新的gcloud组件安装app-engine-go

其他信息:


  1. 没有使用虚拟环境。 li>
  2. 指向dev_appserver的路径:/google/google-cloud-sdk/bin/dev_appserver.py

  3. 我使用Google的控制台Cloudshell

  4. 以下是SDK版本:




    • Google Cloud SDK 192.0.0

    • alpha 2017.09.15

    • 应用引擎转至

    • 应用引擎java 1.9.63
    • app-engine-php

    • 应用程序引擎-python 1.9.67

    • 应用程序引擎-python-extras 1.9。 63
    • beta 2017.09.15

    • bq 2.0.29

    • cbt

    • 云数据存储模拟器1.4.1

    • 核心2018.03.02
    • datalab 20180213

    • docker-credential-gcr

    • gcd-emulator v1beta3-1.0.0

    • gsutil 4.28

    • kubectl

    • pubsub-emulator 2018.02.02


    • ol>

      文件:

      app.yaml

       运行时:python27 
      api_version:1
      线程安全:true

      处理程序:
      - url:/.*
      脚本: main.app

      库:
      - 名称:flask
      版本:0.12
      - 名称:six
      版本: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

       导入记录
      $ b $从瓶子导入Flask
      从床单导入数据

      app =烧瓶(__ name__)

      $ b $ app_route('/')
      def hello():
      return'Hello World!{}'。format(data)


      @ app.errorhandler(500)
      def server_error(e):
      #记录错误a nd stacktrace。
      logging.exception('请求发生错误')
      return'发生内部错误',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软件包,现在它运行得非常好。

      解决方案



我通过上面的评论解决了这个问题:

是的,我在appengine_config.py中有以下内容:

  from google.appengine.ext import vendor 

vendor.add('lib')

我设法通过使用以下代码来解决模块加载问题:



appengine_config.py



  import os 
从google.appengine.ext导入Google
导入供应商

lib_directory = os.path.dirname(__ file__)+'/ lib'

#更改在哪里找到google包(指向lib /目录)
google .__ path__ = [ os.path.join(lib_directory,'google')] + google .__ pat h__

#将任何库安装到lib文件夹中。
vendor.add(lib_directory)


I'm receiving the following error when executing the 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

Odd thing is when I deploy the app, it works fine.

I tried:

  1. dev_appserver.py MY_DIRECTORY
  2. cd /google/google-cloud-sdk/bin/; python dev_appserver.py MY_DIRECTORY
  3. python dev_appserver.py hello_world/
  4. Installed updated gcloud components install app-engine-go

Additional info:

  1. No virtual env is being used.
  2. path to dev_appserver: /google/google-cloud-sdk/bin/dev_appserver.py
  3. I'm using Google's Console Cloudshell
  4. Here are the SDK versions:

    • Google Cloud SDK 192.0.0
    • alpha 2017.09.15
    • app-engine-go
    • app-engine-java 1.9.63
    • app-engine-php " "
    • app-engine-python 1.9.67
    • app-engine-python-extras 1.9.63
    • beta 2017.09.15
    • bq 2.0.29
    • cbt
    • cloud-datastore-emulator 1.4.1
    • core 2018.03.02
    • datalab 20180213
    • docker-credential-gcr
    • gcd-emulator v1beta3-1.0.0
    • gsutil 4.28
    • kubectl
    • pubsub-emulator 2018.02.02

Files:

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

I solve the issue:

The dev_appserver.py was not using the modules in my lib folder. Instead it was using the packages on my computer. To eliminate the issue, I removed all Google packages from my local machine and it works great now.

解决方案

https://github.com/GoogleCloudPlatform/google-auth-library-python/issues/169#issuecomment-315417916

I solved this issue by above comment:

Yes, I have the following in appengine_config.py:

from google.appengine.ext import vendor

vendor.add('lib')

I managed to resolve the module loading issue by using the following instead:

appengine_config.py

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)

这篇关于App Engine未在dev_appserver.py中找到google.auth文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:54