Hello All…I really stuck this last step. I got a code that will plot 2 charts and send attachment on webex teams. I followed the sample code below.
But I got error:
TypeError: expected string or bytes-like object, got 'tuple'
The sample code is below:
import pandas as pd
import matplotlib.pyplot as plt
from io import BytesIO
from webexteamssdk import WebexTeamsAPI
# Assuming you have a DataFrame named df
def generate_plot1(df):
plt.figure(figsize=(8, 6))
plt.plot(df['x'], df['y'])
plt.title('Plot 1')
plt.xlabel('x')
plt.ylabel('y')
plot1_buf = BytesIO()
plt.savefig(plot1_buf, format='png')
plot1_buf.seek(0)
return plot1_buf
def generate_plot2(df):
plt.figure(figsize=(8, 6))
plt.scatter(df['x'], df['y'])
plt.title('Plot 2')
plt.xlabel('x')
plt.ylabel('y')
plot2_buf = BytesIO()
plt.savefig(plot2_buf, format='png')
plot2_buf.seek(0)
return plot2_buf
def send_webex_message(api, room_id_or_email, text, files):
message = {
'roomId': room_id_or_email,
'text': text,
'files': files
}
api.messages.create(**message)
# Initialize the API with your access token
api = WebexTeamsAPI(access_token='YOUR_ACCESS_TOKEN')
# Define the room ID or email address where you want to send the images
room_id_or_email = 'ROOM_ID_OR_EMAIL'
# Generate plots
plot1_buf = generate_plot1(df)
plot2_buf = generate_plot2(df)
# Convert BytesIO buffers to streams
plot1_stream = plot1_buf.read()
plot2_stream = plot2_buf.read()
# Prepare message files
files = [
('plot1.png', plot1_stream, 'image/png'),
('plot2.png', plot2_stream, 'image/png')
]
# Send the message
send_webex_message(api, room_id_or_email, 'Here are the plots!', files)
Any helps would be appreciated!