首页 文章

App Engine中的Google Cloud Pubsub身份验证错误

提问于
浏览
3

我们无法在Google AppEngine上向Google Cloud PubSub主题发布消息 . 使用应用程序默认凭据在本地完美运行 . 但是一旦它部署在Google AppEngine上,就会出现以下错误:

<HttpError 403 when requesting https://pubsub.googleapis.com/v1/projects/our-project-id/topics/our-topic:publish?alt=json returned "The request cannot be identified with a project. Please pass a valid API key with the request.">

我认为它将使用app引擎的服务帐户来访问PubSub API . 这是我们用于创建凭据的代码 .

credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
   credentials = credentials.create_scoped(['https://www.googleapis.com/auth/pubsub'])

http = httplib2.Http()
credentials.authorize(http)
pubsub_service = build('pubsub', 'v1', http=http)

将实际消息发布到PubSub时会引发错误 .

pubsub_service.projects().topics().publish(topic="projects/out-project-id/topics/out-topic", body = { 'messages' : [ { 'data': base64.b64encode(request.get_data()) }]}).execute()

并非相同的流程可以对API调用“ BigQuery ”,因此它不是一般的Google API问题 . 它似乎特定于PubSub ......

1 回答

  • 2

    这是一个罕见的服务帐户,没有嵌入项目ID . 我们修复了您的服务帐户,您现在应该很高兴 . 抱歉,添麻烦了 .

相关问题