【发布时间】:2021-06-17 10:14:27
【问题描述】:
我在谷歌云函数中使用 python 脚本,最近对脚本进行了非常小的更新。然而,在测试中,python 脚本无法将数据写入 bigquery。
以下是我正在使用的库
google-cloud-storage==1.18.0
numpy==1.17.0
dask[dataframe]==2.1.0
pandas==0.25.0
gcsfs==0.2.3
google.auth==1.6.3
google-api-python-client==1.7.11
toolz==0.10.0
fsspec==0.4.1
google-cloud-bigquery[pandas,pyarrow]==1.7.0
下面是我的代码
def cloudfunction(data, context):
from google.cloud import storage
from google.cloud import bigquery
import pandas as pd
import dask.dataframe as dd
import io
import numpy as np
import datetime as dt
from googleapiclient import discovery
from pandas.io.json import json_normalize
import google.auth
import math
# Confirming Oauth #
bigquery_client = bigquery.Client()
#Big Query Destination #
dataset_ref = bigquery_client.dataset('my_dataset')
table_ref = dataset_ref.table('my_datatable')
job_config = bigquery.LoadJobConfig()
job_config.write_disposition = bigquery.WriteDisposition.WRITE_TRUNCATE
df = pd.DataFrame({'account-start': ['2000-01-01', '2000-01-03', '2000-01-02'],
'db-id': [1, 2, 3],
'name': ['Alice', 'Bob', 'Charlie'})
bigquery_client.load_table_from_dataframe(df, table_ref,job_config=job_config).result()
这是错误
Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 449, in run_background_function _function_handler.invoke_user_function(event_object) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 268, in invoke_user_function return call_user_function(request_or_event) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 265, in call_user_function event_context.Context(**request_or_event.context)) File "/user_code/main.py", line 596, in cloudfunction bigquery_client.load_table_from_dataframe(df, table_ref,job_config=job_config).result(): File "/env/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 212, in _items_iter for page in self._page_iter(increment=False): File "/env/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 243, in _page_iter page = self._next_page() File "/env/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 369, in _next_page response = self._get_next_page_response() File "/env/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 419, in _get_next_page_response method=self._HTTP_METHOD, path=self.path, query_params=params File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 479, in api_request timeout=timeout, File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 337, in _make_request method, url, headers, data, target_object, timeout=timeout File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 374, in _do_request return self.http.request( File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 157, in http return self._client._http File "/env/local/lib/python3.7/site-packages/google/cloud/client.py", line 187, in _http self._http_internal.configure_mtls_channel(self._client_cert_source) AttributeError: 'AuthorizedSession' object has no attribute 'configure_mtls_channel'
如果能解决这个问题,我们将不胜感激
【问题讨论】:
标签: python-3.x google-cloud-platform google-cloud-functions