来自App Engine的Google Cloud Pubsub身份验证错误
我们无法将消息发布到Google AppEngine上的Google Cloud PubSub主题。使用应用程序默认凭据在本地完美工作。但是,一旦将它部署到Google AppEngine上,它会提供以下错误:
We're having trouble publishing messages to a Google Cloud PubSub topic on Google AppEngine. Using the Application Default credentials works perfect locally. But once it's deployed on Google AppEngine it gives the following error:
<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。
I would assume that it's will use the service account of app engine to access the PubSub API. Here is the code we used to create the credentials.
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时引发此错误。
The error is thrown when publishing the actual message to 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 ...
Not that the same flow works doing API call's to "BigQuery", so it's not a general Google API problem. It seems to be specific to PubSub...
这是一个非常罕见的情况,没有嵌入项目ID的服务帐户。我们修复了您的服务帐户,您现在应该很好。对不起,麻烦。
It's a rare case of the service account without project id embedded in it. We fixed your service account and you should be good to go now. Sorry for the trouble.