gpt4 book ai didi

python - 带有 Google App Engine 的 Google Prediction API

转载 作者:行者123 更新时间:2023-11-30 22:51:15 25 4
gpt4 key购买 nike

我正在关注这个示例,它的底部有一些代码 https://cloud.google.com/prediction/docs/developer-guide

我使用 Flask 而不是 webapp2,我的代码如下所示:

# [START app]
import logging
from oauth2client.appengine import AppAssertionCredentials
from flask import Flask
import httplib2, webapp2
from oauth2client.appengine import AppAssertionCredentials
from apiclient.discovery import build

http = AppAssertionCredentials('https://www.googleapis.com/auth/prediction').authorize(httplib2.Http())
service = build('prediction', 'v1.6', http=http)


app = Flask(__name__)


@app.route('/')
def hello():
return 'Hello World1!'

@app.route('/add')
def something():
class MakePrediction():
def get(self):
result = service.hostedmodels().predict(project=PROJECT-NAME, hostedModelName=PROJECT-ID, body={'input' {'csvInstance': ['hello']}}).execute()
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Result: ' + repr(result))


@app.errorhandler(500)
def server_error(e):
# Log the error and stacktrace.
logging.exception('An error occurred during a request.')
return 'An internal error occurred.', 500
# [END app]

我不断收到错误:

  File "/Users/morganallen/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/morganallen/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/morganallen/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/morganallen/Desktop/project/flask_app_engine/main.py", line 24
result = service.hostedmodels().predict(project='linear-yen-140912', hostedModelName='language-identifier', body={'input' {'csvInstance': ['hello']}}).execute()
^
SyntaxError: invalid syntax

我做错了什么?

最佳答案

第 24 行缺少一个冒号,小胡萝卜在堆栈跟踪中指向该位置:

  File "/Users/morganallen/Desktop/project/flask_app_engine/main.py", line 24
result = service.hostedmodels().predict(project='linear-yen-140912', hostedModelName='language-identifier', body={'input' {'csvInstance': ['hello']}}).execute()
^

所以这里的解决方案是改变这个:

body={'input' {'csvInstance': ['hello']}}).execute()
^

为此:

body={'input' : {'csvInstance': ['hello']}}).execute()
^

这应该可以解决语法错误。

SyntaxError: invalid syntax

每当出现错误时,不要忽略编译器吐出的所有行。它通常会告诉您问题的确切行,特别是在像这样的简单语法错误的情况下。

关于python - 带有 Google App Engine 的 Google Prediction API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39084362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com