4,144 questions
CSV file not posting to teams channel using webhook url in python code ?
cartmansp
0
Reputation points
Hello Team,
Iam unable to post a CSV file to Teams channel using teams webhook url in python code ? I can see a message post in Teams channel but the csv file is not posting ? Is there a limitation of files that can be posted to Teams channel ? below is the code .Please let me know. Thanks.
import requests
import json
webhook_url = "https://your-webhook-url-here"
csv_file_path = "path/to/your/csv/file.csv"
message = "Here's the latest data"
text = "Please find the attached CSV file for your review"
# Read CSV file contents
with open(csv_file_path, "rb") as f:
csv_data = f.read().decode("UTF-8")
# Define payload
payload = {
"summary": message,
"text": text,
"attachments": [
{
"contentType": "text/csv",
"content": csv_data,
"name": "data.csv"
}
]
}
# Send POST request to webhook URL
response = requests.post(
webhook_url,
data=json.dumps(payload),
headers={'Content-Type': 'application/json'}
)
print(response)
print(response.text)
# Check response status code
if response.status_code != 200:
print(f"Error: {response.status_code} - {response.text}")
else:
print("CSV file posted successfully to Microsoft Teams channel!")
Below is Output response : <Response [200]> , response.text= 1
CSV file size is 17kb.
Thank you.
Microsoft Teams | Development
Sign in to answer