LoginSignup
0
1

More than 3 years have passed since last update.

td-client-python でエンドポイントを指定した場合に、SSL接続でクエリを実行する

Last updated at Posted at 2020-07-21

Python3 で td-client-python を使う際に、エンドポイントがデフォルトではない場合があります。
その場合は以下のようにエンドポイントを指定する必要があります。
例えば TD_ENDPOINT をapi.treasuredata.co.jpとすると、HTTP接続でクエリを実行します。
ここで、SSL接続が必要になる場合があります。

import os

from os.path import join, dirname

import tdclient

from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)

TD_APIKEY = os.environ.get('TD_APIKEY')
TD_ENDPOINT = os.environ.get('TD_ENDPOINT')
DATABASE = 'hoge'

with tdclient.Client(apikey=TD_APIKEY, endpoint=TD_ENDPOINT) as client:
  job = client.query(DATABASE, 'SELECT COUNT(1) FROM fuga', type='presto')
  job.wait()

手元の環境は以下になります。

  • Ubuntu 18.04 LTS
  • Python 3.7.0
  • td-client==0.13.0

※ (2020.7.21 更新)
td-client==1.2.1 以降はデフォルトでSSL接続になるとのことです。

この場合、エンドポイントの指定でhttps://api.treasuredata.co.jpと明示的にSSLを指定する必要があります。

参考になった記事

td-client-python

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1