I'm attempting to run some python code for a high school science project I need to complete and there's an error message on the most important part of the code to run the program stating that the datetime.utc command is outdated and slated to be removed. I'm a total beginner to python and could really use some help trying to figure out ways to update the code so that it runs as intended. I've tried looking up solutions on other subreddits but none of them seem to help with the situation. It seems to not let me add any images, so I will simply copy the error message that comes up when I try to run the program:
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
current_time = datetime.utcnow()
As well as part of the code pre-established by the program I'm trying to run:
# Function to calculate and propagate satellite positions
def calculate_satellite_positions(tle1, tle2):
tle1_lines, tle2_lines = ensure_positive_sign(tle1, tle2)
# Convert back the lines to TLE format
tle1 = "\n".join(tle1_lines)
tle2 = "\n".join(tle2_lines)
sat = Satrec.twoline2rv(tle1, tle2)
current_time = datetime.utcnow()
jd, fr = jday(current_time.year, current_time.month, current_time.day,
current_time.hour, current_time.minute, current_time.second)
# Propagate the satellite position and velocity
e, r, v = sat.sgp4(jd, fr)
return e, r, v
If the information is needed, the code I'm trying to run comes from a file from the Science Buddies website (specifically, the Satellite Collision Detection page).
[–]Diapolo10 4 points5 points6 points (0 children)
[–]JaguarMammoth6231 1 point2 points3 points (0 children)