Side Effects: Troubleshooting
00:00
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.
00:14
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.
00:26
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.
00:42
And we get an interesting ImportError here, cannot import name 'timegm' from 'calendar'. This is where the calendar file is and I believe it’s because when we imported requests,
00:58
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 calendar to my_calendar, and then we’ll open up my_calendar.py.
01:22
I’m going to close the original calendar. And let’s see if we can run my_calendar.py.
01:33
And that did not work either. Maybe I actually have to remove the calendar.py, so let’s try to remove calendar.py.
01:45
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.
01:59
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 ConnectionError.
02:16
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 localhost port 80.
02:29
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.
