title: How to follow someone on Twitter using tweepy/Python?
body: <p>I'm trying to create a Twitter bot using tweepy that will search, like and retweet any status update containing the words "Retweet to enter", and I was successful. However, I would also like the script to follow the person that created the composition (I'm creating this script to try and win contests, and you often need to follow the account that is hosting the contest as well).</p>
  
  <p>My script is pasted below. Currently, the script will indeed follow someone, but it is not the person who created the tweet.</p>
  
  <pre><code>auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
  auth.set_access_token(access_token, access_token_secret)
  api = tweepy.API(auth)
  
  
  user2 = api.me()
  print(user2.name)
  
  def main():
      search = ("Retweet to enter")
      numberoftweets = 5
      for tweet in tweepy.Cursor(api.search, search).items(numberoftweets):
          try:
              tweet.favorite()
              tweet.retweet()
              api.create_friendship(tweet.user.id)
              print("Tweet Retweeted and followed")
          except tweepy.TweepError as e:
              print(e.reason)
          except StopIteration:
              break
  main()
  </code></pre>