Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9025679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:19:58+00:00 2026-06-16T06:19:58+00:00

This is the error I want to catch: Traceback: File /usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py in get_response 111.

  • 0

This is the error I want to catch:

 Traceback:
    File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
      111.                         response = callback(request, *callback_args, **callback_kwargs)
    File "/opt/django/fileupload/views.py" in upload_file
      56.         folder_info = url.split(':')[1] #Extracts folder info to use in the header

    Exception Type: IndexError at /upload_file/
    Exception Value: list index out of range

Tried using:

except (socket.error, paramiko.AuthenticationException, IndexError):
            return render_to_response('reform.html', context_instance=RequestContext(request))

But it doesn’t work.

I am able to catch the socket.error and paramiko.Authentication exceptions but not the IndexError. I am trying to catch the exception in Django. Thanks.

Edit:
Entire try and except block:

try:        
    source = str(username) + "@" + url #Source to list all the files
    add_key = str(username) + "@" + test_url
    add_known_hosts(password, add_key) #Add to the known hosts
    test_ssh(test_url, username, password) #Test Host_name, username and password
    destination = '/home/sachet/files'    
    command = subprocess.Popen(['sshpass', '-p', password, 'rsync', '--recursive', source],
                   stdout=subprocess.PIPE).communicate()[0] #sshpass needs to be installed into the server
    lines = (x.strip() for x in command.split('\n'))
    remote = [x.split(None, 4)[-1] for x in lines if x] #Removes permission from the file listing
    base_name = [os.path.basename(ok) for ok in remote]
    result = subprocess.Popen(['ls', destination], stdout=subprocess.PIPE).communicate()[0].splitlines()

    return render_to_response('thanks.html', {'res1': remote, 'res': result, 'folder': folder_info}, context_instance=RequestContext(request))
except (socket.error, paramiko.AuthenticationException, IndexError):
    return render_to_response('reform.html', context_instance=RequestContext(request)) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:19:59+00:00Added an answer on June 16, 2026 at 6:19 am

    The IndexError is not raised within the try/except block you posted. The IndexError is raised on the line where folder_info is assigned to (line 56 in views.py). You need to move that line of code into your try/except block in order to catch that error.

    File "/opt/django/fileupload/views.py" in upload_file
        56.         folder_info = url.split(':')[1]  <-- This line
    

    Or, better yet, put a separate try/except around the “folder = …” line, just for the IndexError, to make the intention of your code clearer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I can't understand this error I want read this XML file: <?xml version=1.0
I keep getting this error in the $('#savetickets-list') line. I want to dynamically add
i want to import org.apache.commons.io but i'm getting this error: [info] Compiling 1 Java
If I want to trigger an error in my interpreter I call this function:
I want to catch a specific failure of this JavaScript code: var script =
This(*) ObjectLockedException returned from a Java-based web service. I want to catch this specific
I'm getting this PHP warning in my error_log and want to get it fixed.
I want to create a PlayN game, but in Eclipse I get this errors:
Asserts can't be caught. This is good because some errors I don't want to
This error is driving me crazy . I tried freenode #emberjs before asking here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.