2016-08-04 12 views
0

私はドッカーでPythonのトルネードアプリケーションを実行しているよ、とAPIの一部は保存のためにDocumentDBへの接続が含ま:DockerのDocumentDB - "認証トークンは現時点で有効ではありません。"

client = document_client.DocumentClient(config.uri, {'masterKey': config.key}) 
db = next((data for data in client.ReadDatabases() if data['id'] == config.db)) 
coll = next((docs for docs in client.ReadCollections(db['_self']) if docs['id'] == config.collection)) 

承認が完璧に動作し、私が追加と削除を使用してデータベースへの多くの呼び出しを行ってきましたドキュメント。この問題は、私がDockerコンテナを数時間稼働させたままになったとき(正確にどれくらい時間がかかっていないか)、コンテナを夜間に残して午前中にチェックすると、このエラーが発生します。

Traceback (most recent call last): 
tornado1_1 | File "api_app.py", line 76, in <module> 
tornado1_1 |  class UserHandler(BaseHandler): 
tornado1_1 | File "api_app.py", line 82, in UserHandler 
tornado1_1 |  db = next((data for data in client.ReadDatabases() if data['id'] == config.db)) 
tornado1_1 | File "api_app.py", line 82, in <genexpr> 
tornado1_1 |  db = next((data for data in client.ReadDatabases() if data['id'] == config.db)) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/query_iterable.py", line 123, in next 
tornado1_1 |  retry_utility._Execute(self._iterable._client, self._iterable._client._global_endpoint_manager, callback) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/retry_utility.py", line 48, in _Execute 
tornado1_1 |  result = _ExecuteFunction(function, *args, **kwargs) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/retry_utility.py", line 81, in _ExecuteFunction 
tornado1_1 |  return function(*args, **kwargs) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/query_iterable.py", line 114, in callback 
tornado1_1 |  if not self._iterable.fetch_next_block(): 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/query_iterable.py", line 144, in fetch_next_block 
tornado1_1 |  fetched_items = self.fetch_items() 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/query_iterable.py", line 184, in fetch_items 
tornado1_1 |  (fetched_items, response_headers) = self._fetch_function(self._options) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/document_client.py", line 225, in fetch_fn 
tornado1_1 |  options), self.last_response_headers 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/document_client.py", line 2349, in __QueryFeed 
tornado1_1 |  headers) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/document_client.py", line 2206, in __Get 
tornado1_1 |  headers) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/synchronized_request.py", line 168, in SynchronizedRequest 
tornado1_1 |  return retry_utility._Execute(client, global_endpoint_manager, _InternalRequest, connection_policy, request_options, request_body) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/retry_utility.py", line 48, in _Execute 
tornado1_1 |  result = _ExecuteFunction(function, *args, **kwargs) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/retry_utility.py", line 81, in _ExecuteFunction 
tornado1_1 |  return function(*args, **kwargs) 
tornado1_1 | File "/usr/local/lib/python2.7/site-packages/pydocumentdb/synchronized_request.py", line 100, in _InternalRequest 
tornado1_1 |  raise errors.HTTPFailure(response.status, data, headers) 
tornado1_1 | pydocumentdb.errors.HTTPFailure: Status code: 403 
tornado1_1 | {"code":"Forbidden","message":"The authorization token is not valid at the current time. Please create another token and retry (token start time: Thu, 04 Aug 2016 04:30:53 GMT, token expiry time: Thu, 04 Aug 2016 04:45:53 GMT, current server time: Thu, 04 Aug 2016 15:11:11 GMT).\r\nActivityId: af4c602a-9413-4eb3-b270-b8a57fa2d973"} 

あなたが見ることができるように、それはクライアントへの接続を行うことができますが、それはラインdb = next((data for data in client.ReadDatabases() if data['id'] == config.db))で失敗し、サーバとトークン開始時間の間の時間の不一致に関するいくつかの奇妙なエラーがスローされます。コンピュータ(コンテナだけでなく)を再起動すると、不確定な時間の間、再び動作します。それはそれでかどうかは何かを持っている場合

Tip: Resource tokens have a default valid timespan of 1 hour. Token lifetime, however, may be explicitly specified, up to a maximum of 5 hours.

わからない:私はAzure Documentation上で、次のヒントをお読みください。

答えて

0

これは、マシンの時間ドリフト(サーバーと比較して)が違いが1時間になるまで増加し続けるためです。

例外メッセージでは、トークンの開始/終了時刻と現在のサーバー時刻の間のラグを確認できます。

0

authトークンが期限切れになっているようです。もう1つ生成する必要があります。「別のトークンを作成して再試行してください」というエラーメッセージが表示されます。

コンテナを作成するときにトークンを作成しているのでしょうか?コンテナを削除して新しいコンテナを作成しようとする可能性があります。

0

HTTP Status Codes for DocumentDBとあなたの説明によると、例外情報のステータスコード403だからソリューションは、それが例外を処理キャッチ&を経由しての代わりに古いの新しいクライアント接続を作成することですThe authorization token expired.

を意味します。

参考資料として、記事の最後にヒントがあります。

Tip:

Resource tokens have a default valid timespan of 1 hour. Token lifetime, however, may be explicitly specified, up to a maximum of 5 hours.

あなたはトークン有効期間を変更介しヘッダx-ms-documentdb-expiry-secondsの値を指定するRESTのAPI Create a PermissionまたはReplace a Permissionを指すことができます。