I have afunction that works locally on my django app but deployed it raises an list index out of range error
<p>I have a function that raises an error in my logs when I try to use it remotely. I have it run in my background task. the other task I have runs both locally and remotely. heres my code</p>

<p>my my_scraps.py</p>

<pre><code>def liveleak_task():
    url = 'http://www.example1.com/rss?featured=1'
    name = 'live leak'
    live_leaks = [i for i in feedparser.parse(url).entries]
    the_count = len(live_leaks)
    live_entries = [{'href': live_leak.links[0]['href'],
                     'src': live_leak.media_thumbnail[0]['url'],
                     'text': live_leak.title,
                     'comments': live_leak.description,
                     'name': name,
                     'url': live_leak.links[0]['href'], # this is the link to the source
                     'embed': live_leak.links[1]['href'],
                     'author': None,
                     'video': False
                     } for live_leak in live_leaks][10]
    return live_entries


def worldstar_task():
    # scraping from worldstar
    url_to = 'http://www.example2.com'
    html = requests.get(url_to, headers=headers)
    soup = BeautifulSoup(html.text, 'html5lib')
    titles = soup.find_all('section', 'box')

    def make_soup(url):
        the_comments_page = requests.get(url, headers=headers)
        soupdata = BeautifulSoup(the_comments_page.text, 'html5lib')
        comment = soupdata.find('div')
        para = comment.find_all('p')
        kids = [child.text for child in para]
        blu = str(kids).strip('[]')
        return blu

    name = 'World Star'
    cleaned_titles = [title for title in titles if title.a.get('href') != 'vsubmit.php']
    world_entries = [{'href': url_to + box.a.get('href'),
                      'src': box.img.get('src'),
                      'text': box.strong.a.text,
                      'comments': make_soup(url_to + box.a.get('href')),
                      'name': name,
                      'url': url_to + box.a.get('href'),
                      'embed': None,
                      'author': None,
                      'video': True
                      } for box in cleaned_titles][:10]
    return world_entries


def scrambled(a, b):
    site_one = a
    site_two = b
    merged = site_one+site_two
    random.shuffle(merged)

    for entry in merged:
        post = Post()  #
        post.title = entry['text'] #
        title = post.title  #
        if not Post.objects.filter(title=title):
            post.title = entry['text']
            post.name = entry['name']
            post.url = entry['url']
            post.body = entry['comments']
            post.image_url = entry['src']
            post.video_path = entry['embed']
            post.author = None
            post.video = True
            post.status = 'draft'
            post.save()
            post.tags.add("video")
    return merged
</code></pre>

<p>my tasks.py</p>

<pre><code>@app.task
def behind():
    a = worldstar_task()
    b = liveleak_task()
    the_seen = scrambled(a, b)
    return the_seen
</code></pre>

<p>my views.py</p>

<pre><code>def noindex(request):
    behind.delay()
    return redirect('/')
</code></pre>

<p>the traceback</p>

<pre><code>Task blog.tasks.behind[833ef3d3-91e7-4851-99ee-3f7cac4294d6] raised unexpected: IndexError('list index out of range',)
 Traceback (most recent call last):
   File "/app/.heroku/python/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
     R = retval = fun(*args, **kwargs)
   File "/app/.heroku/python/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
     return self.run(*args, **kwargs)
   File "/app/blog/tasks.py", line 91, in behind
     b = liveleak_task()
   File "/app/blog/my_scraps.py", line 397, in liveleak_task
     } for live_leak in live_leaks][10]
   File "/app/blog/my_scraps.py", line 397, in &lt;listcomp&gt;
     } for live_leak in live_leaks][10]
 IndexError: list index out of range
</code></pre>

<p>I tried this</p>

<pre><code>the_count = len(live_leaks)
</code></pre>

<p>and then </p>

<pre><code>for live_leak in live_leaks][the_count -1]
</code></pre>

<p>then</p>

<p>-2 it worked locally but not remotely</p>

<p>then I tried </p>

<pre><code>:10 didn't work remotely or locally 
</code></pre>

<p>didn't work. not sure why that isIf any one knows how I can fix this I'm all ears</p>

<p>I have remedied the problem. I moved the [10] from where it was</p>

<pre><code>    live_leaks = [i for i in feedparser.parse(url).entries]
    the_count = len(live_leaks)
    live_entries = [{'href': live_leak.links[0]['href'],
                 'src': live_leak.media_thumbnail[0]['url'],
                 'text': live_leak.title,
                 'comments': live_leak.description,
                 'name': name,
                 'url': live_leak.links[0]['href'], # this is the link to the source
                 'embed': live_leak.links[1]['href'],
                 'author': None,
                 'video': False
                 } for live_leak in live_leaks][10]&lt;----here
return live_entries
</code></pre>

<p>to </p>

<pre><code>    live_leaks = [i for i in feedparser.parse(url).entries][:10]&lt;-------to here
    the_count = len(live_leaks)

    live_entries = [{'href': live_leak.links[0]['href'],
                 'src': live_leak.media_thumbnail[0]['url'],
                 'text': live_leak.title,
                 'comments': live_leak.description,
                 'name': name,
                 'url': live_leak.links[0]['href'], # this is the link to the source
                 'embed': live_leak.links[1]['href'],
                 'author': None,
                 'video': False
                 } for live_leak in live_leaks]
return live_entries
</code></pre>

<p>and I also added a colon in the front of the 10 like this</p>

<pre><code> [:10]  this selects 10

 [10]   this selects the 10th
</code></pre>

<p>I hope this helps somebody</p>

python django indexing deployment syntax