title: Python - Heroku urllib2.HTTPError
body: <p>I've spent the past day or so working with a group to create a facebook app that computes a user's cluster coefficient (a measure of the interconnectedness of their friends.)<br>
  In order to accomplish this, I need to get the number of mutual friends the user with each of their friends.  Unfortunately, I keep getting a urllib2.HTTPError, and I can't figure out what's going on.  You can access the app (and the error message + traceback) at <a href="https://gentle-stream-3754.herokuapp.com/" rel="nofollow">https://gentle-stream-3754.herokuapp.com/</a>.  </p>
  
  <p>Line 168 in particular was part of the traceback.  I know the code below most likely won't be helpful without context, so that's why I've included link to the app.  </p>
  
  <p>Could it be a problem with user permissions?  Runtime?  </p>
  
  <p>Any help would be appreciated!  Thanks in advance!</p>
  
  <p><strong>EDIT: access_token appears to be a NoneType object, but I'm not entirely sure why.  Could this be causing the urllib2.HTTPError?</strong></p>
  
  <pre><code>164 def clustering_coefficient():
  165 
  166     access_token = get_token()
  167     g = Graph(access_token)
  168     requests = [{'method': 'GET', 'relative_url': 'me/mutualfriends/%s' % x['id']} for x in g.me.friends()['data']]
  169     k_v = len(requests)
  170     if k_v &lt; 2:
  171         return 0.0
  172 
  173     n_v = 0
  174     REQS_PER_POST = 50 
  175     for i in range((k_v // REQS_PER_POST)+1):
  176         result = g.post(batch=json.dumps(requests[i*REQS_PER_POST:(i+1)*REQS_PER_POST]))
  177         for r in result:
  178             body = json.loads(r['body'])
  179             n_v += len(body['data'])
  180 
  181     return 1.0 * n_v / k_v/ (k_v-1)
  </code></pre>
  
  <p>Exception: HTTPError: HTTP Error 400: Bad Request</p>
  
  <p>Traceback:</p>
  
  <pre><code>Traceback (most recent call last)
  File "/app/lib/python2.7/site-packages/flask/app.py", line 1306, in __call__
  return self.wsgi_app(environ, start_response)
  File "/app/lib/python2.7/site-packages/flask/app.py", line 1294, in wsgi_app
  response = self.make_response(self.handle_exception(e))
  File "/app/lib/python2.7/site-packages/flask/app.py", line 1292, in wsgi_app
  response = self.full_dispatch_request()
  File "/app/lib/python2.7/site-packages/flask/app.py", line 1062, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/app/lib/python2.7/site-packages/flask/app.py", line 1060, in full_dispatch_request
  rv = self.dispatch_request()
  File "/app/lib/python2.7/site-packages/flask/app.py", line 1047, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/exampleapp.py", line 168, in clustering_coefficient
  requests = [{'method': 'GET', 'relative_url': 'me/mutualfriends/%s' % x['id']} for x in g.me.friends()['data']]
  File "/app/lib/python2.7/site-packages/facegraph/graph.py", line 157, in __call__
  data = json.loads(self.fetch(self.url | params))
  File "/app/lib/python2.7/site-packages/facegraph/graph.py", line 203, in fetch
  conn = urllib2.urlopen(url, data=data)
  File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
  return _opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 400, in open
  response = meth(req, response)
  File "/usr/local/lib/python2.7/urllib2.py", line 513, in http_response
  'http', request, response, code, msg, hdrs)
  File "/usr/local/lib/python2.7/urllib2.py", line 438, in error
  return self._call_chain(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 372, in _call_chain
  result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 521, in http_error_default
  raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
  </code></pre>