2

このページで Google Developers Academy の App Engine チュートリアルを実行しています: https://developers.google.com/appengine/training/cloud-sql/application_with_local_mysql

これは、ローカルの MySQL インスタンスを使用してゲストブック アプリケーションを構築することに関するものです。チュートリアルの最後にある dev_appserver コマンドを実行して$ app_engine_sdk_path/dev_appserver.py --mysql_socket=mysql_socket_path .、2 つのパスを自分のコンピューターからの実際のパスに置き換えます。その後、端末出力は良好に見えます。

INFO     2013-10-16 05:30:54,815 sdk_update_checker.py:245] Checking for updates to the     SDK.
INFO     2013-10-16 05:30:55,025 sdk_update_checker.py:273] The SDK is up to date.
WARNING  2013-10-16 05:30:55,066 api_server.py:332] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2013-10-16 05:30:55,072 api_server.py:139] Starting API server at: http://localhost:50138
INFO     2013-10-16 05:30:55,076 dispatcher.py:171] Starting module "default" running at: http://localhost:8080
INFO     2013-10-16 05:30:55,081 admin_server.py:117] Starting admin server at: http://localhost:8000

しかし、ブラウザで localhost:8080 に移動した後、ターミナルに大きなエラー メッセージが表示され、多くの行が参照していますwebapp2.py

ERROR    2013-10-16 05:31:04,828 webapp2.py:1528] connect() got an unexpected keyword argument 'user'
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine
default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/Users/patneedham/Documents/AppEngine/mysql-demo/main.py", line 29, in get
conn = get_connection()
File "/Users/patneedham/Documents/AppEngine/mysql-demo/main.py", line 23, in get_connection
user=USER_NAME, password=PASSWORD, charset='utf8')
TypeError: connect() got an unexpected keyword argument 'user'
ERROR    2013-10-16 05:31:04,830 wsgi.py:278] 
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/Users/patneedham/Documents/AppEngine/mysql-demo/main.py", line 29, in get
conn = get_connection()
File "/Users/patneedham/Documents/AppEngine/mysql-demo/main.py", line 23, in get_connection
user=USER_NAME, password=PASSWORD, charset='utf8')
TypeError: connect() got an unexpected keyword argument 'user'
INFO     2013-10-16 05:31:04,837 module.py:608] default: "GET / HTTP/1.1" 500 -

最後のエラー メッセージ行は意味がありません。TypeError: connect() got an unexpected keyword argument 'user'

これについて不平を言っています:

return rdbms.connect(instance=CLOUDSQL_INSTANCE, database=DATABASE_NAME,
                     user=USER_NAME, password=PASSWORD, charset='utf8')

rdbmsインポートステートメントからのものfrom google.appengine.api import rdbmsです。このサイトで Google がホストする rdbms コードを見つけました: https://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/rdbms.py

そこからの接続方法は次のとおりです。

def connect(instance=None, database=None, **kwargs):
  global _instance
  if not instance and _instance:
    instance = _instance

  if 'db' in kwargs and not database:
    database = kwargs.pop('db')

  user = None
  if 'user' in kwargs:
    user = kwargs.pop('user')

  password = None
  if 'password' in kwargs:
    password = kwargs.pop('password')

  if kwargs:
    logging.info('Ignoring extra kwargs to connect(): %r', kwargs)

  return rdbms_apiproxy.connect('unused_address',
                                instance,
                                database=database,
                                user=user,
                                password=password)

それは間違いなくキーワード引数「ユーザー」を期待しているため、この全体が非常にイライラします。また、ローカルにある rdbms ファイルが同じであることを確認しましたが、同じであるため、古いバージョンが原因ではありません。

ここで同じ問題を抱えている別のケースを見つけました: ( https://code.google.com/p/googleappengine/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Component%20Status% 20Stars%20Summary%20Language%20Priority%20Owner%20Log&groupby=&sort=&id=10102 )ですが、未回答です。

4

3 に答える 3

3

ドキュメントが古くなっている可能性があると思います。

connectdev_appserver の起動中にユーザーとパスワードのパラメーターを削除して移動することで、問題を解決しやすくなります。rdbms は実行時にこれら 2 つのパラメーターを実際には使用しないため、開発環境にのみ存在させる方が適切です。

def get_connection():
    # remove user / password
    return rdbms.connect(instance=CLOUDSQL_INSTANCE, database=DATABASE_NAME)

# start the dev server with user/password
$ app_engine_sdk_path/dev_appserver.py --mysql_socket=mysql_socket_path --mysql_user=[MYSQL_USER] --mysql_password=[MYSQL_PASSWORD] . 

# some other variables available.
[--mysql_host MYSQL_HOST] [--mysql_port MYSQL_PORT]
[--mysql_user MYSQL_USER]
[--mysql_password MYSQL_PASSWORD]
[--mysql_socket MYSQL_SOCKET]

Google App Engine は、MySQLdb インターフェイスも提供しました。

https://developers.google.com/appengine/docs/python/cloud-sql/#Python_complete_python_example

if (os.getenv('SERVER_SOFTWARE') and
  os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
  db = MySQLdb.connect(unix_socket='/cloudsql/your-project-id:your-instance-name', user='root')
else:
  db = MySQLdb.connect(host='localhost', user='root')
于 2013-10-25T03:09:32.223 に答える
1

リンク先のコードを見ると、次のようになりますrdbms.py

"""Relational database API for production.

Note that rdbms_mysqldb is the module used in dev_appserver.
"""

次に、でrbdms_mysqldb.py

try:
    import google
    import MySQLdb

    from MySQLdb import *



    __import__('MySQLdb.constants', globals(), locals(), ['*'])
except ImportError:

    def connect(instance=None, database=None):
        logging.error('The rdbms API (Google Cloud SQL) is not available because '
                      'the MySQLdb library could not be loaded. Please see the SDK '
                      'documentation for installation instructions.')

        raise NotImplementedError('Unable to find the MySQLdb library')

else:


    def connect(instance=None, database=None, **kwargs):

したがって、または引数connectなしで定義できる唯一の方法は、インストールしていない場合のようですuser**kwargsMySQLdb

pip install mysql-python
于 2013-10-25T00:16:27.713 に答える