2017-11-15 9 views
1

私はPythonで単純な標準のアプリケーションエンジンを配備しようとしています。そこからpython bigqueryクライアントを介してbigqueryクエリを作成しようとしています。アプリケーションエンジンの標準環境呼び出しbigquery python

コードは、これらのように簡単です:

from __future__ import absolute_import 
import webapp2 
import os 
from google.cloud import bigquery 

class MainPage(webapp2.RequestHandler): 
    def get(self): 


    client = bigquery.Client(project = "ancient-ceiling-125223") 
    project_name = str(client.project) 

    query_job = client.query("select 1") 

    assert query_job.state == 'RUNNING' 

    iterator = query_job.result(timeout= 30) 

    rows = list(iterator) 

    self.response.write('nothing to see %s' % (project_name)) 


app = webapp2.WSGIApplication(
[('/', MainPage)], debug=True) 

エラーログ:エラーがダミーのクエリ要求

*('Connection broken: IncompleteRead(209 bytes read)', IncompleteRead(209 bytes read)) (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py:1528) 
Traceback (most recent call last): 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ 
    return handler.dispatch() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/main.py", line 35, in get 
    query_job = client.query("select 1") 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/cloud/bigquery/client.py", line 986, in query 
    job._begin(retry=retry) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/cloud/bigquery/job.py", line 397, in _begin 
    method='POST', path=path, data=self._build_resource()) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/cloud/bigquery/client.py", line 271, in _call_api 
    return call() 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/api_core/retry.py", line 260, in retry_wrapped_func 
    on_error=on_error, 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/api_core/retry.py", line 177, in retry_target 
    return target() 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/cloud/_http.py", line 290, in api_request 
    headers=headers, target_object=_target_object) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/cloud/_http.py", line 183, in _make_request 
    return self._do_request(method, url, headers, data, target_object) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/cloud/_http.py", line 212, in _do_request 
    url=url, method=method, headers=headers, data=data) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/google/auth/transport/requests.py", line 186, in request 
    method, url, data=data, headers=request_headers, **kwargs) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/requests/sessions.py", line 502, in request 
    resp = self.send(prep, **send_kwargs) 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/requests/sessions.py", line 652, in send 
    r.content 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/requests/models.py", line 825, in content 
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes() 
    File "/base/data/home/apps/s~ancient-ceiling-125223/20171115t104156.405543624689752939/lib/requests/models.py", line 750, in generate 
    raise ChunkedEncodingError(e) 
ChunkedEncodingError: ('Connection broken: IncompleteRead(209 bytes read)', IncompleteRead(209 bytes read))* 
+0

これは認証のようではありません問題に。テストのためだけに、 '' select 1 ''のような非常に単純なクエリを試してみたらうまくいきますか?また、フレックス環境で動作していると思いますが正しいですか? –

+0

単純なクエリはどちらも動作しません。私は標準的な環境で走っています。 –

+0

あなたが表示しているコードは、 'query_job:'文の 'for row 'を示すトレースバックと一致しません。問題はその省略によって覆い隠されるかもしれません。より単純な例があれば、トレースバックを投稿してください。 –

答えて

3

に表示されます私はそれがクライアントライブラリのBigQueryのpythonを使用して動作させることができませんでした、標準のアプリエンジン環境で働いていたことがわかりました。

from __future__ import absolute_import 
import webapp2 

from googleapiclient.discovery import build 
from oauth2client.client import GoogleCredentials 


class MainPage(webapp2.RequestHandler): 
    def get(self): 

    credentials = GoogleCredentials.get_application_default() 
    service = build('bigquery', 'v2', credentials=credentials) 

    datasets = service.datasets().list(projectId="ancient-ceiling-125223").execute() 

    self.response.write('datasets: %s' % datasets) 


app = webapp2.WSGIApplication(
    [('/', MainPage)], debug=True) 
+2

行く方法!だから私は環境について尋ねたのですが、GoogleのクラウドAPIをStandardのために働かせることはできませんでした。ただgoogleapiclientだけです。私がお勧めするものは、リクエストの外にサービスを作成することです(この[repo](https://github.com/WillianFuks/example_dataproc_twitter/tree/master/gae/exporter)には、私がそれを行う方法の例があります)。同様に、クエリが60秒以上かかる場合、この方法は機能しません。クエリをスケジュールする必要があるかもしれません。 –

+0

ありがとうございました。レポは本当に役立ちます –

関連する問題