Side Effects: Troubleshooting
I’m going to drop down and create an entry point of
if __name__ == '__main__': we’ll just call
get_holidays(). And let’s print that return value.
Let’s open up the terminal and run the program called
calendar.py. And we get this
AssertionError and this looks like something left over.
Right, so we made this
saturday and we’re testing, “Is it a weekday?” So let’s do an
assert not, so this should resolve this
AssertionError. Let’s try that again.
And we get an interesting
cannot import name 'timegm' from 'calendar'. This is where the
calendar file is and I believe it’s because when we imported
there’s probably another module called
calendar, so I think we need to actually change the name of this file. So let’s go ahead and I’m just going to copy
my_calendar, and then we’ll open up
I’m going to close the original
calendar. And let’s see if we can run
And that did not work either. Maybe I actually have to remove the
calendar.py, so let’s try to remove
And then we’ll try this once again. Okay, great. So that was just because the
requests underneath the hood was using a module called
calendar.py and there was a naming conflict.
So we’ve renamed the file
my_calendar.py and now we’re actually getting a response from
requests. Since I don’t have a
/holidays endpoint running on my machine—and I’m assuming you don’t either—you’re going to get a
This is a
requests.exception, we have—let’s see what it says.
Failed to establish a new connection […]
Connection refused, because I don’t have this endpoint running on
So this is what happens when you run
get_holidays() and there is no server at this particular URL.
Become a Member to join the conversation.