google.api_core.exceptions: 403 调用者没有权限
google.api_core.exceptions: 403 The caller does not have permission
我正在使用 google 云自动表 api,当我对方法执行 url 请求时,它给我这个错误:
google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
参数是正确的,为什么它显示错误!
@app.route('/model_train',methods=['GET','POST'])
def model_train():
project_id = 'myproject'
compute_region = 'us-central1'
model_id = 'TBL7912987273010'
file_path = 'E:/downloads/Dataset-entrainement-demain_ai_demonstrateur_attrition_Oct19_Copie.csv'
score_threshold = '0.5'
automl_client = automl.AutoMlClient()
model_full_id = automl_client.model_path(
project_id, compute_region, model_id
)
prediction_client = automl.PredictionServiceClient()
params = {}
if score_threshold:
params = {"score_threshold": score_threshold}
with open(file_path, "rt") as csv_file:
content = csv.reader(csv_file)
for row in content:
values = []
for column in row:
values.append({'number_value': float(column)})
payload = {
'row': {'values': values}
}
response = prediction_client.predict(model_full_id, payload)
print("Prediction results:")
for result in response.payload:
print("Predicted class name: {}".format(result.display_name))
print("Predicted class score: {}".format(result.classification.score))
谁能帮帮我!
添加一个正式的答案,基本上问题是在 GCP IAM 部分为用户帐户设置的权限。
首先,需要为项目here
启用automl API
然后您需要 generate credentials 并将它们作为环境变量传递。您可以使用 os 库在文件顶部添加环境变量:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/to/file.json"
我正在使用 google 云自动表 api,当我对方法执行 url 请求时,它给我这个错误:
google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
参数是正确的,为什么它显示错误!
@app.route('/model_train',methods=['GET','POST'])
def model_train():
project_id = 'myproject'
compute_region = 'us-central1'
model_id = 'TBL7912987273010'
file_path = 'E:/downloads/Dataset-entrainement-demain_ai_demonstrateur_attrition_Oct19_Copie.csv'
score_threshold = '0.5'
automl_client = automl.AutoMlClient()
model_full_id = automl_client.model_path(
project_id, compute_region, model_id
)
prediction_client = automl.PredictionServiceClient()
params = {}
if score_threshold:
params = {"score_threshold": score_threshold}
with open(file_path, "rt") as csv_file:
content = csv.reader(csv_file)
for row in content:
values = []
for column in row:
values.append({'number_value': float(column)})
payload = {
'row': {'values': values}
}
response = prediction_client.predict(model_full_id, payload)
print("Prediction results:")
for result in response.payload:
print("Predicted class name: {}".format(result.display_name))
print("Predicted class score: {}".format(result.classification.score))
谁能帮帮我!
添加一个正式的答案,基本上问题是在 GCP IAM 部分为用户帐户设置的权限。 首先,需要为项目here
启用automl API然后您需要 generate credentials 并将它们作为环境变量传递。您可以使用 os 库在文件顶部添加环境变量:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/to/file.json"