2022-04-14

How to get api_codes in Tweepy with API v2?

v1 api you could do

print(e.response)
print(e.api_errors)
print(e.api_codes)
print(e.api_messages)

with v2 (client) the Error message doesn't seem to have any of this. Any ideas how to get at the api_codes and api_messages. I've been googling for hours and am not finding any clear reference on how to move this to V2. Very frustrating.

With code sample as requested. I hope I'm missing something simple.

try:
   status = api.update_status(status="test", in_reply_to_status_id = 1514213177210425346 , auto_populate_reply_metadata=True)
except tweepy.errors.Forbidden as e:
    print(e.response)
    print(e.api_errors)
    print(e.api_codes)
    print(e.api_messages)

# <Response [403]>
# [{'code': 433, 'message': 'The original Tweet author restricted who can reply to this Tweet.'}]
# [433]
# ['The original Tweet author restricted who can reply to this Tweet.']
# Deleted or not visible.
    
try:
    response = client.create_tweet(text="test", in_reply_to_tweet_id=1514213177210425346)
except tweepy.errors.Forbidden as e:
    print(e.response)
    print(e.api_errors)
    print(e.api_codes)
    print(e.api_messages)

# <Response [403]>
# []
# []
# []


No comments:

Post a Comment