title: How to overcome Error 429: Too Many Requests for Twitter API on Heroku server
body: <p>I'm trying to run an application on Heroku, which does the following request:</p>
  
  <pre><code>curl 'https://api.twitter.com/2/timeline/conversation/{TWEET_ID_PARAMETER}.json?include_profile_interstitial_type=1&amp;include_blocking=1&amp;include_blocked_by=1&amp;include_followed_by=1&amp;include_want_retweets=1&amp;include_mute_edge=1&amp;include_can_dm=1&amp;include_can_media_tag=1&amp;skip_status=1&amp;cards_platform=Web-12&amp;include_cards=1&amp;include_ext_alt_text=true&amp;include_reply_count=1&amp;tweet_mode=extended&amp;include_entities=true&amp;include_user_entities=true&amp;include_ext_media_color=true&amp;include_ext_media_availability=true&amp;send_error_codes=true&amp;simple_quoted_tweet=true&amp;count=20&amp;ext=mediaStats%2ChighlightedLabel&amp;include_quote_count=true' -H 'authorization: Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA' -H 'x-guest-token: {X_GUEST_TOKEN_PARAMETER}'
  </code></pre>
  
  <p>To do that, I'm trying to get the x-guest-token with the following Python code:</p>
  
  <pre><code>def obtain_x_guest_token_for_twitter():
      data = parse.urlencode({}).encode()
      req = Request('https://api.twitter.com/1.1/guest/activate.json', data=data)
      req.add_header('Authorization', 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA')
      req.add_header('User-Agent', 'Firefox')
      content = urlopen(req)
      x_guest_token = json.load(content)["guest_token"]
      return x_guest_token
  </code></pre>
  
  <p>Where <code>AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA</code> is the public Bearer token</p>
  
  <p>I can make the script run on my local machine, but when I try to run it on my Heroku app it gives me a response of <code>HTTP Error 429: Too Many Requests</code></p>
  
  <p>Can the heroku public IP be the problem? Maybe blacklisted?
  If so, can I change the request to make it work? I have a registered Twitter application, I've tried with application authorization but doesn't work.
  Thanks in advance.</p>