title: Twitter API returned a 401 (Unauthorized) when trying to get users's friends on twitter
body: <p>I'm using the following code which for a while worked like charm, but recently in 9 of the 10 attempts I'm getting error from twitter api</p>
  
  <pre><code>from twython import Twython, TwythonError                                                                             
  from pymongo import Connection                                                                                        
  import pika, time                                                                                                     
  
  connection = Connection("host")
  connection.admin.authenticate('admin', 'passwords')
  db = connection['tweets']
  
  consumer_key="key"
  consumer_secret="secret"
  
  access_token="token"
  access_token_secret="secret_token"
  
  t = Twython(app_key=consumer_key,
              app_secret=consumer_secret,
              oauth_token=access_token,
              oauth_token_secret=access_token_secret 
             )
  
  Q ='download_friends'
  
  r_connection = pika.BlockingConnection(pika.ConnectionParameters(
                 'host'))
  channel = r_connection.channel()
  channel.queue_declare(queue= Q, 
                  arguments={'x-message-ttl':600000})   
  
  
  while 1:
      method_frame, header_frame, id = channel.basic_get(Q)
      if db.friends.find_one({"_id": id}) != None:
          print "Panic, user already exists"
          continue
      try:
          r = t.get_friends_list(user_id = id)
      except Exception as ex:
          print ex, id
      else:
          print id
          r['_id'] = id
          r['time'] = time.time()
          db.friends.save(r)
  
      time.sleep(121)
  </code></pre>
  
  <blockquote>
    <p>Twitter API returned a 401 (Unauthorized), An error occurred
    processing your request.</p>
  </blockquote>
  
  <p>Here is a stacktrace</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/twython/endpoints.py", line 290, in get_friends_list
      return self.get('friends/list', params=params)
    File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 230, in get
      return self.request(endpoint, params=params, version=version)
    File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 224, in request
      content = self._request(url, method=method, params=params, api_call=url)
    File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 194, in _request
      retry_after=response.headers.get('retry-after'))
  twython.exceptions.TwythonAuthError: Twitter API returned a 401 (Unauthorized), An error occurred processing your request.
  </code></pre>
  
  <p>I the remaining 1 attempt I'm actually getting a user's friends. </p>
  
  <p>I've googled a bit and corrected time on the machine (as they say one of the most common causes of this error), yet error still persists.</p>
  
  <p>Also there is minimal not working example:</p>
  
  <pre><code>twitter = Twython('API key', 'API secret', oauth_version=2)
  ACCESS_TOKEN = twitter.obtain_access_token()
  
  print ACCESS_TOKEN
  
  t = Twython('API key', access_token=ACCESS_TOKEN)
  r = t.get_friends_list(user_id = 'id')
  </code></pre>
  
  <p>It is able to get ACCESS_TOKEN but nothing more.</p>