Filter icalendar events based on a time frame breaks because of datetime comparison

I am trying to pull events from an ics file within the next month but making my own datetime and comparing to the datetime in the ics file doesn’t seem to be working and is giving the error TypeError: can't compare offset-naive and offset-aware datetimes

I tried the answers found here but still get the same error. Below is the code I am using.

def read_from_cal():
    g = open('calendar.ics', 'rb')
    gcal = Calendar.from_ical(g.read())
    year = datetime.now().year
    month = datetime.now().month
    day = datetime.now().day
    hour = datetime.now().strftime("%H")
    minute = datetime.now().strftime("%M")

    next_month = datetime(int(year), int(month)+1, int(day), int(hour), int(minute), 0, tzinfo=pytz.UTC)
    #next_month = next_month.replace(tzinfo=pytz.UTC)
    for component in gcal.walk():
        if component.name == "VEVENT":
            # time printed out in format:
            #      year-month-day hour:min:sec
            summ = component.get('summary')
            start = component.get('dtstart').dt
            end = component.get('dtend').dt
            if now <= start <= next_month:
                print("Worked")
                print(summ, start, end)


I’ve tried both with using replace to change my time to utc and just putting it in the next_month variable itself and they both give the same error above.

I’ve also tried this and this to no avail.

Answer

I have tried with a .ics file generated here, so could not be the same problem, but in some cases start is a datetime.datetime and in other cases is a datetime.date.

This solution worked with my .ics file

from icalendar import Calendar
from datetime import datetime
from dateutil.relativedelta import relativedelta


def read_from_cal():
    g = open('example.ics', 'rb')
    gcal = Calendar.from_ical(g.read())
    today = datetime.now()
    next_month =  today + relativedelta(months=1)
    for component in gcal.walk():
        if component.name == "VEVENT":
            summ = component.get('summary')
            start = component.get('dtstart').dt
            end = component.get('dtend').dt
            if isinstance(start, datetime):
                start = start.replace(tzinfo=None)
                if start <= next_month:
                    print("Worked (datetime)")
                    print(summ, start, end)
            else:
                # some events are stored as a date
                if start <= next_month.date():
                    print("Worked (date)")
                    print(summ, start, end)

read_from_cal()