我是这个谷歌App引擎的新手。我写了一个小的python代码,旨在连接谷歌云中的数据库。不幸的是我收到了这个错误。
Traceback (most recent call last):
File "/home/revanth/Projects/workspace/project2/connect.py", line 28, in <module>
main()
File "/home/revanth/Projects/workspace/project2/connect.py", line 19, in main
user='revanth'
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'revanth'@'76.183.80.171' (using password: NO)")
这是我在python中的代码
import googleapiclient
import MySQLdb
import os
#from google.storage.speckle.python.api import rdbms_googleapi
def main():
env = os.getenv('SERVER_SOFTWARE')
if (env and env.startswith('Google App Engine/')):
# Connecting from App Engine
db = MySQLdb.connect(
unix_socket='/cloudsql/citric-cistern-97118:geoeq',
user='revanth')
else:
# Connecting from an external network.
# Make sure your network is whitelisted
db = MySQLdb.connect(
host='173.194.232.179',
port=3306,
user='revanth'
)
cursor = db.cursor()
cursor.execute('select * from Whether')
rows = cursor.fetchall()
print rows
if __name__ == '__main__':
main()
请帮帮我。
答案 0 :(得分:2)
授予对App Engine应用程序的访问权限:
注意:为了确保低延迟,通过在创建实例时选择首选位置或配置现有实例,可以使Google Cloud SQL实例尽可能靠近指定的App Engine应用程序。这仅适用于在美国和欧盟地区创建的实例。 单击“保存”以应用更改。
答案 1 :(得分:0)
我找到了解决方案。我只需要添加0.0.0.0/0以允许所有外部IP地址连接它。
以下是链接:https://cloud.google.com/sql/docs/access-control
我需要在选项中指定密码。