Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django ModuleNotFoundError:没有名为';谷歌';在GCP应用程序中_Django_Google App Engine_Google Cloud Platform - Fatal编程技术网

Django ModuleNotFoundError:没有名为';谷歌';在GCP应用程序中

Django ModuleNotFoundError:没有名为';谷歌';在GCP应用程序中,django,google-app-engine,google-cloud-platform,Django,Google App Engine,Google Cloud Platform,我有一个Django应用程序,我正试图部署到GCP。当我在本地运行该应用程序时,它运行得非常好,并且它的部署对GCP没有任何问题(通过gcloud app deploy)。当我打开网页时,由于“ModuleNotFoundError:没有名为“google”的模块”,我得到了这个错误“502坏网关502 nginx”。我一直无法找到如何正确地将谷歌导入我的GCP应用程序。如需了解更多详细信息,欢迎提供帮助 以下是解析的堆栈跟踪(通过GCP调试器): ModuleNotFoundError:没有名

我有一个Django应用程序,我正试图部署到GCP。当我在本地运行该应用程序时,它运行得非常好,并且它的部署对GCP没有任何问题(通过gcloud app deploy)。当我打开网页时,由于“ModuleNotFoundError:没有名为“google”的模块”,我得到了这个错误“502坏网关502 nginx”。我一直无法找到如何正确地将谷歌导入我的GCP应用程序。如需了解更多详细信息,欢迎提供帮助

以下是解析的堆栈跟踪(通过GCP调试器):

ModuleNotFoundError:没有名为“google”的模块
在(/srv/socha_web/settings.py:14)
已删除帧的at调用(:219)
at exec_模块(:728)
在加载解锁时(:677)
在“查找”和“加载”时解锁(:967)
在_查找和_加载(:983)
at_gcd_导入(:1006)
在导入模块处(/opt/python3.7/lib/python3.7/importlib/uuu init_uuu.py:127)
在uuu init uuuu(/env/lib/python3.7/site packages/django/conf/uuuu init.py:142)
在安装时(/env/lib/python3.7/site-packages/django/conf/_-init__;.py:63)
在uuu getattr_uuuu(/env/lib/python3.7/site packages/django/conf/uuuuu init_uuuuuuu.py:76)
在安装时(/env/lib/python3.7/site packages/django/_init__.py:19)
已删除帧的at调用(:219)
at exec_模块(:728)
在加载解锁时(:677)
在“查找”和“加载”时解锁(:967)
在_查找和_加载(:983)
at_gcd_导入(:1006)
在导入模块处(/opt/python3.7/lib/python3.7/importlib/uuu init_uuu.py:127)
在导入应用程序时(/env/lib/python3.7/site-packages/gunicorn/util.py:358)
加载时(/env/lib/python3.7/site packages/gunicorn/app/wsgiapp.py:39)
加载时(/env/lib/python3.7/site packages/gunicorn/app/wsgiapp.py:49)
在wsgi(/env/lib/python3.7/site packages/gunicorn/app/base.py:67)
加载时的wsgi(/env/lib/python3.7/site packages/gunicorn/workers/base.py:144)
在init_进程中(/env/lib/python3.7/site packages/gunicorn/workers/base.py:119)
在spawn_worker(/env/lib/python3.7/site packages/gunicorn/arbiter.py:583)
这是我的settings.py文件(我擦除了所有密钥):

导入操作系统
从google.oauth2导入服务_帐户
#在项目内部构建如下路径:os.path.join(BASE_DIR,…)
BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(u文件_u)))
#快速启动开发设置-不适合生产
#看https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
#安全警告:请对生产中使用的密钥保密!
SECRET\u KEY='SECRET\u KEY'
#安全警告:不要在生产环境中打开调试的情况下运行!
#如果在本地进行测试,请将其切换为True
调试=错误
允许的_主机=['*',”https://app-number.wl.r.appspot.com",]
CORS\u ORIGIN\u ALLOW\u ALL=True
#社交身份验证配置启动
社会认证管道=(
“社交核心.管道.社交授权.社交详细信息”,
“social_core.pipeline.social_auth.social_uid”,
“允许社交核心.管道.社交身份验证.身份验证”,
“social_core.pipeline.social_auth.social_user”,
“social_core.pipeline.user.get_username”,
“social_core.pipeline.user.create_user”,
“社交核心.pipeline.socialauth.associate用户”,
“社交核心.管道.社交身份验证.加载额外数据”,
“social_core.pipeline.user.user_details”,
'socha_web.pipeline.profile.create_profile'
)
身份验证\u后端=[
“social_core.backends.facebook.FacebookOAuth2”,
'django.contrib.auth.backends.ModelBackend',
]
LOGIN\u URL='LOGIN'
登录\重定向\ URL='搜索'
注销\u URL='LOGOUT'
注销\u重定向\u URL='login'
社交网站(AUTH\u POSTGRES\u JSONFIELD)=True
#最终需要将其更改为环境变量
社交身份验证FACEBOOK密钥='fb\U身份验证密钥'#应用程序ID
社交网站_AUTH_FACEBOOK _SECRET='fb_SECRET'#应用程序SECRET
社交网站(FACEBOOK)的范围=[“用户朋友”,“电子邮件”]#添加此项
社交网站FACEBOOK个人资料额外参数={{添加此项
“字段”:“id、姓名、电子邮件、图片。键入(大)、链接、朋友”
}
社交身份验证用户名完整电子邮件=True
社交网站授权FACEBOOK额外数据=[#添加此项
('name','name'),
(“电子邮件”、“电子邮件”),
(‘图片’,‘图片’),
('link','profile_url'),
(“朋友”、“朋友”)
]
社交网站认证FACEBOOK API版本='7.0'
#社交身份验证配置结束
#GAE SETTINGS.py执行以下“允许的\u主机=['*']
#应用程序定义
已安装的应用程序=[
“api.apps.ApiConfig”,
“django.contrib.admin”,
“django.contrib.auth”,
“django.contrib.contenttypes”,
“django.contrib.sessions”,
“django.contrib.messages”,
“django.contrib.staticfiles”,
“护卫舰”,
“rest_框架”,
“社交活动”,
“前端登录”,
“前端配置文件”,
“前端写作”,
“前端_墙”,
“前端_提要”,
“前端页脚”,
“大师风格”,
]
REST_框架={
“默认分页类”:“rest\u framework.PAGINATION.PageNumberPagination”,
“页面大小”:10,
“默认权限类”:[
'rest_framework.permissions.IsAuthenticated',
]
}
中间件=[
'django.middleware.security.SecurityMiddleware',
“django.contrib.sessions.middleware.SessionMiddleware”,
'django.middleware.common.CommonMiddleware',
“django.middleware.csrf.CsrfViewMiddleware”,
“corsheaders.middleware.Corsmidlware”,
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.xFrameOptions中间件',
]
ROOT_URLCONF='socha_web.url'
模板=[
{
'BACKEND':'django.template.backends.django.DjangoTemplates',
“DIRS”:[],
“应用程序目录”:正确,
“选项”:{
“上下文处理器”:[
“django.template.context_processors.debug”,
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
“social_django.context_processors.backends”,添加以下内容
“social_django.context_processors.login_redirect”,#添加以下内容
],
ModuleNotFoundError: No module named 'google'
at <module> (/srv/socha_web/settings.py:14)
at _call_with_frames_removed (<frozen importlib._bootstrap>:219)
at exec_module (<frozen importlib._bootstrap_external>:728)
at _load_unlocked (<frozen importlib._bootstrap>:677)
at _find_and_load_unlocked (<frozen importlib._bootstrap>:967)
at _find_and_load (<frozen importlib._bootstrap>:983)
at _gcd_import (<frozen importlib._bootstrap>:1006)
at import_module (/opt/python3.7/lib/python3.7/importlib/__init__.py:127)
at __init__ (/env/lib/python3.7/site-packages/django/conf/__init__.py:142)
at _setup (/env/lib/python3.7/site-packages/django/conf/__init__.py:63)
at __getattr__ (/env/lib/python3.7/site-packages/django/conf/__init__.py:76)
at setup (/env/lib/python3.7/site-packages/django/__init__.py:19)
at _call_with_frames_removed (<frozen importlib._bootstrap>:219)
at exec_module (<frozen importlib._bootstrap_external>:728)
at _load_unlocked (<frozen importlib._bootstrap>:677)
at _find_and_load_unlocked (<frozen importlib._bootstrap>:967)
at _find_and_load (<frozen importlib._bootstrap>:983)
at _gcd_import (<frozen importlib._bootstrap>:1006)
at import_module (/opt/python3.7/lib/python3.7/importlib/__init__.py:127)
at import_app (/env/lib/python3.7/site-packages/gunicorn/util.py:358)
at load_wsgiapp (/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py:39)
at load (/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py:49)
at wsgi (/env/lib/python3.7/site-packages/gunicorn/app/base.py:67)
at load_wsgi (/env/lib/python3.7/site-packages/gunicorn/workers/base.py:144)
at init_process (/env/lib/python3.7/site-packages/gunicorn/workers/base.py:119)
at spawn_worker (/env/lib/python3.7/site-packages/gunicorn/arbiter.py:583)
import os
from google.oauth2 import service_account
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret_key'

# SECURITY WARNING: don't run with debug turned on in production!
# IF TESTING LOCALLY, SWITCH THIS TO True
DEBUG = False

ALLOWED_HOSTS = ['*', "https://app-number.wl.r.appspot.com",]
CORS_ORIGIN_ALLOW_ALL = True


# SOCIAL AUTH CONFIG START
SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
    'socha_web.pipeline.profile.create_profile'
)
AUTHENTICATION_BACKENDS = [
    'social_core.backends.facebook.FacebookOAuth2',
    'django.contrib.auth.backends.ModelBackend',
]


LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'search'
LOGOUT_URL = 'logout'
LOGOUT_REDIRECT_URL = 'login'

SOCIAL_AUTH_POSTGRES_JSONFIELD = True


# eventually need to change this to environment variables
SOCIAL_AUTH_FACEBOOK_KEY = 'fb_auth_key'        # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = 'fb_secret' # App Secret
SOCIAL_AUTH_FACEBOOK_SCOPE = ['user_friends', 'email'] # add this
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {       # add this
  'fields': 'id, name, email, picture.type(large), link, friends'
}
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
SOCIAL_AUTH_FACEBOOK_EXTRA_DATA = [                 # add this
    ('name', 'name'),
    ('email', 'email'),
    ('picture', 'picture'),
    ('link', 'profile_url'),
    ('friends', 'friends')
]
SOCIAL_AUTH_FACEBOOK_API_VERSION = '7.0'


# SOCIAL AUTH CONFIG END



# GAE SETTINGS.py does the following "ALLOWED_HOSTS=['*']
# Application definition

INSTALLED_APPS = [
    'api.apps.ApiConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'rest_framework',
    'social_django',
    'frontend_login',
    'frontend_profile',
    'frontend_writing',
    'frontend_wall',
    'frontend_feed',
    'frontend_footer',
    'master_style_js',
]

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ]
}

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'socha_web.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends', # add this
                'social_django.context_processors.login_redirect', # add this
            ],
        },
    },
]

WSGI_APPLICATION = 'app.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

# [START db_setup]
if os.getenv('GAE_APPLICATION', None):
    # Running on production App Engine, so connect to Google Cloud SQL using
    # the unix socket at /cloudsql/<your-cloudsql-connection string>
    # root user(postgres)
    # root password
    # can add users in cloud console, just leaving as root for now
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'HOST': '/cloudsql/app-number:us-west1:app-instance',
            'USER': 'user',
            'PASSWORD': 'password',
            'NAME': 'name',
        }
    }
else:    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'HOST': '127.0.0.1',
            'PORT': '5432',
            'NAME': 'app',
            'USER': 'user',
            'PASSWORD': 'password',
        }
    }

# [END db_setup]

# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# [START staticurl]
# Fill in your cloud bucket and switch which one of the following 2 lines
# is commented to serve static content from GCS
# STATIC_URL = 'https://storage.googleapis.com/<your-gcs-bucket>/static/'
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_BUCKET_NAME = 'upload_bucket'
GS_PROJECT_ID = "app-number"
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
    "socha_web/app-key.json"
)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = 'static'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
google-api-python-client