title: No JSON object could be decoded - django - pythonanywhere
body: <p>I am working on a django app which fetches data from facebook graph api and plots a network graph of it. The app runs fine locally but it gives me an error <code>No JSON object could be decoded</code> when I host it on <a href="https://www.pythonanywhere.com" rel="nofollow">pythonanywhere</a>. Also, being a newbie to pythonanywhere I don't know how to print the errors on console.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import urllib,json
  from django.shortcuts import render
  from main.forms import InputForm
  from django.http import HttpResponseRedirect
  
  def main(request):
      if request.method == 'POST': # If the form has been submitted
          input_form = InputForm(request.POST)
          if input_form.is_valid():
              cd = input_form.cleaned_data
              actoken = cd['access_token']
              keyword = cd['keyword']
              url = "https://graph.facebook.com/search?q="+keyword+"&amp;type=post&amp;fields=likes.fields(name).limit(10),comments,message&amp;limit=5&amp;access_token="+actoken
              fetch = urllib.urlopen(url).read()
              print fetch # don't know the response
              data = json.loads(fetch)
              return HttpResponseRedirect('/graph/')
          else:
              input_form = InputForm(request.POST)
              return render(request, 'index.html', {
                  'input_form': input_form,
              })
      else:
          input_form = InputForm()
          return render(request, 'index.html', {
              'input_form': input_form,
          })
  </code></pre>
  
  <p>Here is the stack trace:</p>
  
  <p>Traceback:</p>
  
  <pre><code>File "/home/architv/.virtualenvs/django16/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
    114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/architv/fb-network-graph/fbnetworkgraph/main/views.py" in main
    15.             data = simplejson.loads(fetch)
  File "/usr/lib/python2.7/json/__init__.py" in loads
    338.         return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py" in decode
    365.         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py" in raw_decode
    383.             raise ValueError("No JSON object could be decoded")
  
  Exception Type: ValueError at /main/
  Exception Value: No JSON object could be decoded
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I went through the server log file as suggested by glenn and found this:</p>
  
  <pre><code>2014-04-05 09:22:22 https://graph.facebook.com/search?q=ukraine&amp;type=post&amp;fields=likes.fields(name).limit(10),comments,message&amp;limit=5&amp;access_token=CAACEdEose0cBAIhZBJSXHTHOoGZCFZC2xbPDNuNKX9NIksZBMQudtzN2A7o4op5ZBkOhYTZAS6JFcn5lQMNY94nhntZAhmA4DZAWuVg0wqHVHI3VQToq9yhHeQZBL75BgaPMNIbUj9XKQ7ICKJeM3R5YAShXjBxPZAcmbfmxcARFQZA0UjartHP3lWpWCR2wRjJ8WwZD
  2014-04-05 09:22:22 &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt;&lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;title&gt;ERROR: The requested URL could not be retrieved&lt;/title&gt; &lt;style type="text/css"&gt;&lt;!--   /*#012 Stylesheet for Squid Error pages#012 Adapted from design by Free CSS Templates#012 http://www.freecsstemplates.org#012 Released for free under a Creative Commons Attribution 2.5 License#012*/#012#012/* Page basics */#012* {#012#011font-family: verdana, sans-serif;#012}#012#012html body {#012#011margin: 0;#012#011padding: 0;#012#011background: #efefef;#012#011font-size: 12px;#012#011color: #1e1e1e;#012}#012#012/* Page displayed title area */#012#titles {#012#011margin-left: 15px;#012#011padding: 10px;#012#011padding-left: 100px;#012#011background: url('http://www.squid-cache.org/Artwork/SN.png') no-repeat left;#012}#012#012/* initial title */#012#titles h1 {#012#011color: #000000;#012}#012#titles h2 {#012#011color: #000000;#012}#012#012/* special event: FTP success page titles */#012#titles ftpsuccess {#012#011backgro
  2014-04-05 09:22:22   body :lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; } :lang(he) { direction: rtl; }  --&gt;&lt;/style&gt; &lt;/head&gt;&lt;body id=ERR_UNSUP_REQ&gt; &lt;div id="titles"&gt; &lt;h1&gt;ERROR&lt;/h1&gt; &lt;h2&gt;The requested URL could not be retrieved&lt;/h2&gt; &lt;/div&gt; &lt;hr&gt;  &lt;div id="content"&gt; &lt;p&gt;The following error was encountered while trying to retrieve the URL: &lt;a href="https://graph.facebook.com/search?"&gt;https://graph.facebook.com/search?&lt;/a&gt;&lt;/p&gt;  &lt;blockquote id="error"&gt; &lt;p&gt;&lt;b&gt;Unsupported Request Method and Protocol&lt;/b&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Squid does not support all request methods for all access protocols. For example, you can not POST a Gopher request.&lt;/p&gt;  &lt;p&gt;Your cache administrator is &lt;a href="mailto:webmaster?subject=CacheErrorInfo%20-%20ERR_UNSUP_REQ&amp;amp;body=CacheHost%3A%20glenn-liveproxy1%0D%0AErrPage%3A%20ERR_UNSUP_REQ%0D%0AErr%3A%20%5Bnone%5D%0D%0ATimeStamp%3A%20Sat,%2005%20Apr%202014%2009%3A21%3A47%20GMT%0D%0A%0D%
  </code></pre>