我在Google的一個git倉庫中發現了一些關於bigquery插入的示例代碼。應用程序引擎上線程安全的客戶端庫(python)
如果你看到的app.yaml它說這個代碼應該是線程安全的,但如果我在客戶端的lib的文檔(https://developers.google.com/api-client-library/python/guide/thread_safety)lokking它不應該是線程安全的。我現在有點困惑,我的下面的代碼是線程安全的還是不是? 它運行在應用程序引擎標準環境中。
import pprint
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
# Create the bigquery api client
service = build('bigquery', 'v2', credentials=credentials)
response = service.datasets().list(projectId='PROJECTID').execute()
pprint.pprint(response)
---- ----更新添 的回答後,我改變了我的代碼如下。這個現在應該是好的:
import pprint
from googleapiclient.discovery import build
from oauth2client.contrib.appengine import AppAssertionCredentials
import httplib2
credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/bigquery')
# Create the bigquery api client
service = build('bigquery', 'v2')
def get():
# authorize http object with client credentials
http = credentials.authorize(httplib2.Http())
response = service.datasets().list(projectId='PROJECTID').execute(http=http)
pprint.pprint(response)
請你看看更新嗎?謝謝 –