tweepy.error.TweepError: [{u'message': u'Text parameter is missing.', u'code': 38}]


I am using tweepy twitter api for python, while using it i got some error, I am not able to use send_direct_message(user/screen_name/user_id, text) this method

Here is my code:-

import tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

API = tweepy.API(auth)

user = API.get_user('SSPendse')
id = 773436067231956992
text="Message Which we have to send must have maximum 140 characters, If it is Greater then the message will be truncated upto 140 characters...."
# re = API.send_direct_message(screen_name, text)
re = API.send_direct_message(id, text)
print re

got following error:-

Traceback (most recent call last):
  File "", line 36, in <module>
    re = API.send_direct_message(id, text)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/", line 245, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/", line 229, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{u'message': u'Text parameter is missing.', u'code': 38}]

What will be mistake done by me...???

I also have another problem related to tweepy, How can I moved to page two or got more followers in following code

user = API.get_user('Apple')
followers = API.followers(,-1)
for follower in followers:
    print follower,'\t',i

if I run the code I got only 5000 followers however if I use user.followers_count it gives 362705 followers (This no. may be changes while You check it) How can I see remaining followers

Thank You... :)

To solve your first error, replace re = API.send_direct_message(id, text) with re = API.send_direct_message(id, text=text). This function only works if you give it the message as a named parameter. The parameter name you need here is "text", so you might want to change your variable name to avoid confusion. Also, I just tried it, since you are sending a direct message, not a tweet, it will not be truncated to only the first 140 characters.

For your second question, this should do the trick, as explained here:

followers = []
for page in tweepy.Cursor(API.followers, screen_name='Apple').pages():
    time.sleep(60) #this is here to slow down your requests and prevent you from hitting the rate limit and encountering a new error

This video can help you solving your question :)
By: admin