Question: I ' m getting an error code on the fromAddress line. Here's the code I ' m using. I ' m not sure how to

I'm getting an error code on the fromAddress line. Here's the code I'm using. I'm not sure how to fix the issue. Thanks for the help.
import csv
import subprocess
import ezgmail
from ping3 import ping
# Function to ping an IP address
def ping_ip(ip):
try:
result = subprocess.run(['ping','-n','3', ip], capture_output=True, text=True, timeout=5)
if "Request timed out" in result.stdout:
return None
else:
return float(result.stdout.split('Average =')[1].split('ms')[0])
except subprocess.TimeoutExpired:
return None
# Read IP addresses from CSV file
ipFile = open('ip.csv')
ipReader = csv.DictReader(ipFile)
msg =""
for row in ipReader:
ip = row['ip']
ping_time = ping(ip)
print(ip,'\t', ping_time)
# instead of printing the ip and ping_time, how can we
# build a message that contains this info?
#How can we send an email with a message we've built?
# Ping each IP address and store the data
ping_data ={}
for ip in ipFile:
ping_result = ping_ip(ip)
ping_data[ip]= ping_result
# Send an email with the ping data
email_content ="
".join([f"{ip}{ping}" for ip, ping in ping_data.items()])
subject = "Daily Ping Report"
recipient_email = "efincher@mail.pima.edu" # Replace with your email address
ezgmail.init(tokenFile="token.json", credentialsFile="credentials.json", fromAddress="efincher@mail.pima.edu")
ezgmail.send(recipient_email, subject, email_content)
print("Email sent successfully!")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!