Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Stefan Bekirov
3,479 PointsProblem with try
from twitter import (
tweet,
MessageTooLongError,
CommunicationError,
)
message = input("What would you like to tweet? ")
# Your code here
def tweet(text):
print(text)
tweet(message)
try:
tweet(message)
except CommunicationError:
print("An error occurred attempting to connect to Twitter. Please try again!"
7 Answers
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsPython is very sinsitive about indentation. It seems like the most of your code uses 4 spaces as indentation but the print statement inside the except block is indented with 8 spaces
Stefan Bekirov
3,479 PointsI tried Sir and put indentation of 4 spaces but still this problem on my running test:
FAIL: test_error_handled (main.TestFunctionWithCommunicationsErrorExecution)
Traceback (most recent call last): File "/usr/local/pyenv/versions/3.6.4/lib/python3.6/unittest/mock.py", line 1179, in patched return func(*args, **keywargs) File "", line 18, in test_error_handled AssertionError: 'try again' not found in 'til that gushers are ravioli\ntil that gushers are ravioli' : Make sure you output the Try again message on CommunicationError
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsJust noticed that you're also missing a closing )
print("An error occurred attempting to connect to Twitter. Please try again!" # <----
If this is not the problem then try to write the challenge description and your current code
Stefan Bekirov
3,479 Pointsfrom twitter import ( tweet, MessageTooLongError, CommunicationError, )
message = input("What would you like to tweet? ")
Your code here
def tweet(text): print(text)
tweet(message) try: tweet(message) except CommunicationError: print("An error occurred attempting to connect to Twitter. Please try again!")
Stefan Bekirov
3,479 PointsI DON"T GET THIS MISTAKE
Traceback (most recent call last): File "/usr/local/pyenv/versions/3.6.4/lib/python3.6/unittest/mock.py", line 1179, in patched return func(*args, **keywargs) File "", line 18, in test_error_handled AssertionError: 'try again' not found in 'til that gushers are ravioli\ntil that gushers are ravioli' : Make sure you output the Try again message on CommunicationError
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsThe challenges are sometimes very sensitive to what you should print and what not to print.
From what I can see:
- line 18
- Make sure you output the Try again message on CommunicationError
try:
# something here
except CommunicationError:
print('Try again')
If this doesn't work then please share the challenge description or paste a link to the challenge
Stefan Bekirov
3,479 PointsI appreciate your time and help but I guess there is some problem with the exercise. I did everything and still same error
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsTry share the challenge description or a link to the challenge
Stefan Bekirov
3,479 PointsHow is it work? I’m pretty new here so I don’t know.how the challenge works
jon nikolakakis
1,639 Pointsanswer is following,
from twitter import (
tweet,
MessageTooLongError,
CommunicationError,
)
message = input("")
try:
tweet(message)
except CommunicationError:
print("An error occurred attempting to connect to Twitter. Please try again!")
Stefan Bekirov
3,479 PointsStefan Bekirov
3,479 PointsThank you very much Sir!!! I’m going to try if it’s work