Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23334

Getting "The fcm.googleapis.com API requires a quota project, which is not set by default" when running a Google Cloud Function locally

$
0
0

I'm trying to test a Google Cloud Function that sends messages to users. The relevant code is:

cred = credentials.ApplicationDefault()firebase_admin.initialize_app(cred, {"projectId": "redacted_project_id",})@functions_framework.httpdef send_messages(request):    fcm_tokens = request_json.get('fcmTokens')    message_text = request_json.get('message')    message = messaging.MulticastMessage(        data={'message': message_text},        tokens=fcm_tokens,    )    response = messaging.send_multicast(message)    if response.success_count > 0:        logging.info("Message sent successfully")        return jsonify({'success': True, 'message': 'Message sent successfully!'}), 200    else:        logging.warning("Failed to send message. Responses: %s", len(response.responses))        for index, resp in enumerate(response.responses):            if not resp.success:                logging.error("Failed to send message to token %s: %s", fcm_tokens[index], resp.exception)        return jsonify({'success': False, 'message': 'Failed to send message'}), 500

I'm running this locally with functions-framework --target=send_messages. When calling the function, I see the output:

WARNING - Failed to send message. Responses: 2ERROR - Failed to send message to token e7...N6T2:APA...0bh: Your application is authenticating by using local Application Default Credentials. The fcm.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .ERROR - Failed to send message to token banana: Your application is authenticating by using local Application Default Credentials. The fcm.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .

(Redacted part of the token)

I have no idea why this is happening-

  • The page linked in the error says to run gcloud auth application-default set-quota-project YOUR_PROJECT (which I did)
  • echo $GOOGLE_CLOUD_PROJECT returns the correct project id
  • cat /home/$USER/.config/gcloud/application_default_credentials.json has the correct quota_project_id (was set by running gcloud auth application-default login)
  • My role in the Google Cloud Project is "Owner"

Viewing all articles
Browse latest Browse all 23334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>