【问题标题】:cloud sql connection error (OperationalError)云sql连接错误(OperationalError)
【发布时间】:2014-12-08 04:13:40
【问题描述】:

在谷歌应用引擎上上传应用程序后出现以下错误。 但是在我的本地机器上一切正常

OperationalError at /users/

(2004, "Can't create TCP/IP socket (-1)")

Request Method:     GET
Request URL:    http://arctic-anvil-728.appspot.com/users/
Django Version:     1.4.13
Exception Type:     OperationalError
Exception Value:    

(2004, "Can't create TCP/IP socket (-1)")

Exception Location:     /base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/connections.py in __init__, line 190
Python Executable:  /base/data/home/runtimes/python27/python27_dist/python
Python Version:     2.7.5
Python Path:    

['/base/data/home/apps/s~arctic-anvil-728/1.379355097665075133',
 '/base/data/home/runtimes/python27/python27_dist/lib/python27.zip',
 '/base/data/home/runtimes/python27/python27_dist/lib/python2.7',
 '/base/data/home/runtimes/python27/python27_dist/lib/python2.7/plat-linux2',
 '/base/data/home/runtimes/python27/python27_dist/lib/python2.7/lib-tk',
 '/base/data/home/runtimes/python27/python27_dist/lib/python2.7/lib-old',
 '/base/data/home/runtimes/python27/python27_dist/lib/python2.7/lib-dynload',
 '/base/data/home/runtimes/python27/python27_dist/lib/python2.7/site-packages',
 '/base/data/home/runtimes/python27/python27_lib/versions/1',
 '/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4',
 '/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4',
 '/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0',
 '/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3',
 '/base/data/home/runtimes/python27/python27_lib/versions/third_party/webob-1.1.1',
 '/base/data/home/runtimes/python27/python27_lib/versions/third_party/yaml-3.10']

Server time:    Mon, 13 Oct 2014 13:45:19 +0000

请帮我解决这个问题。

提前致谢

【问题讨论】:

    标签: django sockets google-app-engine python-2.7 google-cloud-sql


    【解决方案1】:

    感谢托尼的回答,是的,我已经阅读了文档,但没有运气:( 我正在使用带有谷歌应用引擎的 Django 休息框架 请查看我的“settings.py”文件:

    """
    
    For more information on this file, see
    https://docs.djangoproject.com/en/1.6/topics/settings/
    
    For the full list of settings and their values, see
    https://docs.djangoproject.com/en/1.6/ref/settings/
    """
    
    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    import os
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    
    
    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
    
    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = '*****************************************'
    
    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = True
    
    TEMPLATE_DEBUG = True
    
    ALLOWED_HOSTS = ['*']
    
    
    # Application definition
    
    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'rest_framework',
    )
    
    MIDDLEWARE_CLASSES = (
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        #'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    )
    
    ROOT_URLCONF = 'my-rest.urls'
    
    WSGI_APPLICATION = 'my-rest.application'
    
    
    # Database
    # https://docs.djangoproject.com/en/1.6/ref/settings/#databases
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'INSTANCE': 'appid:sql_instance_id',
            'NAME': '********',
            'USER': '********',
            'HOST': '***.**.**.**',
            'PASSWORD': '*********',
        }
    }
    
    #DATABASES = {
    #    'default': {
    #        'ENGINE': 'django.db.backends.mysql',
    #        'NAME': 'app_engine',
    #        'USER': 'root',
    #        'HOST': 'localhost',
    #        'PASSWORD': ''
    #    }
    #}
    
    # Internationalization
    # https://docs.djangoproject.com/en/1.6/topics/i18n/
    
    LANGUAGE_CODE = 'en-us'
    
    TIME_ZONE = 'UTC'
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = True
    
    REST_FRAMEWORK = {
        # Use Django's standard `django.contrib.auth` permissions,
        # or allow read-only access for unauthenticated users.
        'DEFAULT_PERMISSION_CLASSES': [
            'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
        ]
    }
    
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.6/howto/static-files/
    
    STATIC_URL = '/static/'
    

    如果有人想要我的示例代码,我可以提供。 请告诉我这段代码有什么问题。

    【讨论】:

    【解决方案2】:

    请查看documentation。从 App Engine 连接时,您应该使用 unix_socket。

    【讨论】:

    • 我已经分享了我的settings.py,请看一下
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 2021-10-27
    • 2022-02-01
    • 1970-01-01
    相关资源
    最近更新 更多