2737

Setting an object in the Django cache API fails due to pickle error

I'm trying to manually set an object in the Django cache API but it fails (i think due to pickling?) The object is given to me by a third party, my code is:

def index(request, template_name="mytemplate.htm"): user_list = cache.get("user_list_ds") if user_list is None: # this is the expensive bit I'm trying to cache # given to me by a third part user_list = graffiti.user_list("top", 100).responseObj().blocks() cache.set("user_list_ds", user_list, 10*60) # 10 minutes return render_to_response(template_name, { 'user_list' : user_list,}, context_instance = RequestContext(request))

When I run this I get an error;

Can't pickle <type 'etree._Element'>: import of module etree failed in - cache.set("user_list_ds", user_list, 10*60) # 10 minutes

I'm very new to python, and I'm wondering how best to resolve this, do i need to pickle something first?

Answer1:

It appears that you need to install ElementTree, because the pickle operation tries and fails to import the etree module.

UPDATE: Looking at it further, are you actually trying to cache document nodes? If you're trying to cache the data from the node, you probably need to do some processing of the value you're currently storing in user_list.

Recommend

  • Add new users from a text file in bash script
  • Django_permissions, how to template my menu item based on the permissions?
  • How to add extra data to a Django model for display in template?
  • How do I test this code in RSpec?
  • Display all record on django-filter page startup
  • How to replace the Key for sort field in a meteor collection query?
  • Django - Simple search form
  • Access parent template data with Flow Router
  • jQuery - events won't fire for dynamically created tab elements
  • how can I make a server communicate with more than 1 client at the same time?
  • Formatting a TimeSpan to look like a time zone offset
  • what is for…in statement in javascript
  • GData Youtube : obtaining thumbnails
  • CakePHP 3 losing Auth Session
  • Cache is client side or server side?
  • Making a panel persist despite click on page opened in browser
  • User matching with current data
  • pyspark substring and aggregation
  • app_Offline.htm doesn't work for subfolders of my application in IIS
  • Reporting crash on UITableview reloadData
  • Exception handling as per java coding standards
  • Timeout on a php Peg Puzzle solver
  • redirect user after update in class based view in django
  • Show records ordered with maximum price first in PHP & MySQL
  • How to generate an asynchronous reset verilog always blocks with chisel
  • Google Calendar Api is not showing event list
  • Python function to read variable length blocks of data from file while open
  • How does the HEXTORAW() function work? What is the algorithm?
  • Calculate time difference in hh:mm:ss with simple javascript/jquery
  • TFS 2015 - Waiting for an agent to be requested
  • How to synchronize jQuery dialog box to act like alert() of Javascript
  • Debugging VB6 Code From Visual Studio 2010
  • Marklogic : Query response time is very high
  • print() is showing quotation marks in results
  • Allowing both email and username for authentication
  • Get one-time binding to work for ng-if
  • Illegal mix of collations for operation for date/time comparison
  • How do you troubleshoot character encoding problems?
  • A cron job substitute?
  • Django query for large number of relationships