Skip to content

Commit f7ef49c

Browse files
Add better error handling to x-bot for debugging authentication issues
1 parent a3a918f commit f7ef49c

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

apps/x-bot/bot.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,31 @@ def year_progress_bar():
3232
return post
3333

3434
def tweet(message):
35-
client = tweepy.Client(
36-
consumer_key=os.getenv('API_KEY'),
37-
consumer_secret=os.getenv('API_SECRET'),
38-
access_token=os.getenv('ACCESS_TOKEN'),
39-
access_token_secret=os.getenv('ACCESS_TOKEN_SECRET')
40-
)
41-
42-
client.create_tweet(text=message)
35+
try:
36+
print(f"Attempting to tweet with credentials:")
37+
print(f"API_KEY: {os.getenv('API_KEY')[:5]}...")
38+
print(f"API_SECRET: {os.getenv('API_SECRET')[:5]}...")
39+
print(f"ACCESS_TOKEN: {os.getenv('ACCESS_TOKEN')[:5]}...")
40+
print(f"ACCESS_TOKEN_SECRET: {os.getenv('ACCESS_TOKEN_SECRET')[:5]}...")
41+
42+
client = tweepy.Client(
43+
consumer_key=os.getenv('API_KEY'),
44+
consumer_secret=os.getenv('API_SECRET'),
45+
access_token=os.getenv('ACCESS_TOKEN'),
46+
access_token_secret=os.getenv('ACCESS_TOKEN_SECRET')
47+
)
48+
49+
response = client.create_tweet(text=message)
50+
print(f"Tweet posted successfully! Tweet ID: {response.data['id']}")
51+
return response
52+
except Exception as e:
53+
print(f"Error posting tweet: {str(e)}")
54+
print(f"Error type: {type(e).__name__}")
55+
if hasattr(e, 'response') and hasattr(e.response, 'text'):
56+
print(f"Response text: {e.response.text}")
57+
raise
4358

4459
if __name__ == "__main__":
4560
message = year_progress_bar()
61+
print(f"Generated message: {message}")
4662
tweet(message)

0 commit comments

Comments
 (0)