【问题标题】:OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)") [closed]OperationalError:(2003,“无法连接到'localhost'上的MySQL服务器([Errno 111]连接被拒绝)”)[关闭]
【发布时间】:2019-04-10 14:22:18
【问题描述】:

我正在使用谷歌应用引擎

我的设置文件

import pymysql  # noqa: 402
pymysql.install_as_MySQLdb()

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>
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '/cloudsql/connectionstring',
            'USER': 'myusername',
            'PASSWORD': 'mypasswor',
            'NAME': 'mydbname',
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '127.0.0.1',
            'PORT': '3306',
            'USER': 'username',
            'PASSWORD': 'mypassword',
            'NAME': 'dbname',
        }
    }

工作正常..

现在我尝试使用 social-auth-app-django 实现 google 身份验证

从谷歌重定向后显示以下错误:

OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] 连接被拒绝)") 连接 (/env/lib/python3.7/site-packages/pymysql/connections.py:629)

【问题讨论】:

  • 检查您传递给 Google 的重定向 URL。您确定它试图将您送回您的 App Engine 实例,而不是您的本地开发环境吗? /cloudsql/connectionstring 实际上并不是您要使用的连接字符串,对吧?
  • @kungphu google 重定向到我的公共域而不是本地主机,我认为我不应该透露我的连接字符串,它仅在从 google 重定向时才起作用。
  • 您只有一个settings.py 文件,还是有单独的devproduction 设置文件?
  • 你找到解决这个问题的方法了吗?

标签: python django python-3.x google-app-engine pymysql


【解决方案1】:

编辑以下配置文件 /etc/my.cnf

添加这一行:bind-address=127.0.0.1

应该可以解决问题

【讨论】:

  • 这对我有用,谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-06-07
  • 1970-01-01
  • 2015-08-26
  • 2021-06-08
  • 1970-01-01
  • 1970-01-01
  • 2018-03-30
  • 2018-10-12
相关资源
最近更新 更多