I’m building a Python application to monitor Gmail messages in real-time and analyze them for security threats. My setup includes two separate Python files - one for processing existing emails and another for handling incoming live messages.
The Problem: My live message handler isn’t showing any activity when new emails arrive, even though my historical email processor works perfectly and retrieves all recent messages. Cloud Run logs confirm POST 200 responses when test emails are sent, and local testing with curl commands works fine. However, nothing appears in my local development environment logs.
My Setup:
- Flask webhook deployed on Google Cloud Run
- Unauthenticated access enabled during deployment
- Pub/Sub subscription points to my Cloud Run endpoint
- Application containerized with Docker
- Flask configured for host=0.0.0.0, port=8080
Here’s my simplified webhook code:
from flask import Flask, request, jsonify
import base64
import logging
import json
server = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)
@server.route('/notification-handler', methods=['POST'])
def process_gmail_notification():
try:
# Debug incoming request details
logging.debug(f"Request headers: {dict(request.headers)}")
logging.debug(f"Request payload: {request.data.decode('utf-8')}")
# Process incoming JSON data
payload = request.get_json(silent=True)
if not isinstance(payload, dict):
logging.error("Received invalid JSON structure.")
return jsonify({"error": "Invalid JSON structure received."}), 400
# Decode the notification content
notification_content = payload.get("message", {}).get("data")
if notification_content:
decoded_content = base64.urlsafe_b64decode(notification_content)
content_string = decoded_content.decode("utf-8")
logging.info(f"Notification content: {content_string}")
else:
logging.warning("Missing notification content in request.")
return jsonify({"error": "Missing notification content."}), 400
return jsonify({"result": "Processed", "content": content_string}), 200
except Exception as error:
logging.error(f"Processing error: {error}")
return jsonify({"error": str(error)}), 500
if __name__ == '__main__':
server.run(host='0.0.0.0', port=8080, debug=True)
What could be causing this disconnect between Cloud Run receiving the notifications and my local development environment not seeing them?