'the python code doesn't send the file to the slack channel on airflow, but does it in a local servel
I have a working code for sending a report pdf to a slack, it works if I execute it locally, but the same code doesn't send anything in airflow. There is no error and it prints all the lines till the end.
Would appreciate any help greatly as I can't seem to notice the error
if last_update == date.today():
print('the dashboard {} is up to date'.format(wb_name))
for view_item in wb_views:
print(view_item)
if view_item.name not in selected_pages:
print (view_item.name)
server.views.populate_pdf(view_item, pdf_req_option)
tf = io.BytesIO()
tf.write(view_item.pdf)
tf.seek(0)
merger.append(tf)
else:
continue
temp_file = io.BytesIO()
merger.write(temp_file)
temp_file.seek(0)
f = {'file': ('{0}-{1}.pdf'.format(wb_name, report_date), temp_file, 'pdf')}
response = requests.post(url='https://slack.com/api/files.upload',
data={'token': bot_token,
'channels': slack_channel,
'media': f,
'title': '{} {}'.format(wb_name, report_date),
'initial_comment' :'Hello. Here is the dashboard with all the main metrics {0}'.format(report_date)},
headers={'Accept': 'application/json'}, files=f)
print('check the channel')
else:
# if the dashboard was updated
result = client.chat_postMessage(channel='testing_slc_bot',
text="""OMG {0} wasn't sent to the channel {1} :sloth_shock:.
\nPlease go to the link https://tableau.ozon.ru/#/workbooks/312/views and update the dashboard.
\nAnd then please trigger the dag""".format(wb_name, slack_channel))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
