'How do I send a PUP/SUB message on GCP
My function below is supposed to trigger the sending of a pub/sub message. However, I get a key error. I am not sure why it is throwing this error.
def run(event, context):
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
week = datetime.date.today().isocalendar()[1]
year = datetime.date.today().year
file_name = f"Times week {year}.{week}.xlsx"
file_path = f"/tmp/{file_name}"
data = DataIngestion().get_data(pubsub_message)
data = pd.DataFrame.from_records(data)
data.drop(columns='_type', inplace=True)
for col in data.columns:
if "Open" in col or "Close" in col:
data[col] = pd.to_datetime(data[col], format= '%H:%M', errors="coerce").dt.time
data[col] = data[col].replace(np.nan, 'closed', regex=True)
check_unique(data)
data.to_excel(file_path, index=False, encoding='utf-8')
filetoSend(file_path, file_name, week)
Here is the error:
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 171, in view_func
function(data, context)
File "/workspace/main.py", line 92, in run
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
KeyError: 'data'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
