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 7900201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:54:37+00:00 2026-06-03T08:54:37+00:00

I need to pass a dictionary from a python script to a Django app.

  • 0

I need to pass a dictionary from a python script to a Django app. Therefore I’m using the following:

def sendDataToApp(rssi_readings):
        url = 'http://localhost:8000/world/rssi_import'
        data = urllib.urlencode(rssi_readings)
        req = urllib2.Request(url, data)
        response = urllib2.urlopen(req)

The rssi_readings is the actual dictionary. Now in my Django app I have an url set up and do have a view defined as follows:

def rssi_import(request, rssi_readings):
    print "Test"
    cache.set('rssi_angle_reading', rssi_readings)
    return HttpResponse("Data submitted")

I’m not even seeing the print, so I think the server can’t handle the data. After that I want to store the data in a cache, which shouldn’t be a problem.

My dev server is up and running, but when I run the script I get an HTTP ERROR 500 with the following:

  File "autoorientation.py", line 245, in <module>
    main()
  File "autoorientation.py", line 241, in main
    sendDataToApp(rssi_readings)
  File "autoorientation.py", line 199, in sendDataToApp
    response = urllib2.urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 406, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 444, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR

I was hoping anyone can tell me what the problem is? Even trying to post a simple string didn’t work. Thank you!!!

EDIT:

Here is my url.py. I have it split up in 2 files, but this should be the important one:

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns('world.views',

    url(r'^$', 'index'),
    url(r'^setup/$', 'setup'),
    url(r'^redoscan/$', 'redoScan'),
    url(r'^rssi_import/$', 'rssi_import'),
)

EDIT2:

Ok, I have just tried to not send the data in the request from the script and now I actually get something. The dev server says:

[02/May/2012 15:32:46] "GET /world/rssi_import HTTP/1.1" 301 0
[02/May/2012 15:32:46] "GET /world/rssi_import/ HTTP/1.1" 200 14

So I’m very sure that the script works and my urls to, but somehow the stupid thing doesn’t know what to do with the data.

  • 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-03T08:54:38+00:00Added an answer on June 3, 2026 at 8:54 am

    Ok, I finally figured it out.

    @Dan H You were right with the trailing slash, it actually made it big difference. Once removed I actually got a 403 error.

    After checking out with I got an 403 error I found something about CSRF, just as @Aleksej Vasinov already mentioned in one of his comments. I actually didn’t even know I was using that, but it seems to be almost the standard way in the settings file. I now have an CSRF exempt for this specific view and everything works fine.

    I can now post data and am very happy. Thank you for all your great ideas. I’ll be back on stackoverflow. 🙂

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

Sidebar

Related Questions

How can I pass a dictionary to a python script from another python script
I need to pass a Scripting.Dictionary between my C# app and another app. I
I need to pass an array from JavaScript to a page method in C#.
I need to pass configuration settings to an AddIn created using the Managed AddIn
I need to know it to correctly get filedata from POST dictionary. I want
I pass a dictionary to my Django Template, Dictionary & Template is like this
I am using .NET 4.0, MVC3 and entity framework 4.0 I need to pass
I need to pass all my current page cookies to other server with request:
I need to pass some values to the fseek() method in C which are
I need to pass an ID and a password to a batch file at

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.