Stephanie Lippel575 Points
Practice Creating and Using Functions in Python, Challenge Task 2 of 3
I get the msg "AssertionError: False is not True: Make sure you catch the CommunicationError in a try except block."
""" This is importing a function named `tweet` from a file that we unfortunately don't have access to change. You use it like so: >>> tweet("Hello this is my tweet") If the function cannot connect to Twitter, the function will raise a `CommunicationError` If the message is too long, the function will raise a `MessageTooLongError` """ from twitter import ( tweet, MessageTooLongError, CommunicationError, ) message = input("What would you like to tweet? ") tweet(message) try: tweet("message") except CommunicationError: print("An error occurred attempting to connect to Twitter. Please try again!")
YZ L4,772 Points
there are two mistakes that I can see: 1: tweet(message)is outside the block 2: tweet("message")is a string, not a variable, so your code will simply print 'message' and no t the input
rydavimTreehouse Moderator 17,155 Points
You've got the right idea, but you want to be building on the previous step of the challenge. Try structuring your
try except block around the line from Task 1.
message = input("What would you like to tweet? ") tweet(message) # This is from Task 1 - good job! try: tweet("message") # You should still be using your successful code from the previous task here. except CommunicationError: print("An error occurred attempting to connect to Twitter. Please try again!")
Hopefully that helps get you un-stuck, but if you're still running into problems let me know and we can walk through a solution. Nice work, and happy coding!