我正在使用google cloud automl表api,当我对方法执行url请求时,会出现此错误:
google.api_core.exceptions.PermissionDenied:403呼叫者没有权限
参数正确,为什么它会向我显示该错误!
@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))
有人可以帮我吗!
答案 0 :(得分:0)
添加一个正式答案,基本上,问题在于在GCP IAM部分为用户帐户设置的权限。 首先,需要为项目here
启用automl API然后,您需要generate credentials并将其作为环境变量传递。您可以使用os库将环境变量添加到文件顶部:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/to/file.json"