python - passing django request object to celery task -


i have task in tasks.py so:

@app.task def location(request): .... 

i trying pass request object directly few task so:

def tag_location(request):     tasks.location.delay(request)     return jsonresponse({'response': 1}) 

i getting error can't serialized guess? how fix this? trouble have file upload objects .. not simple data types.

because request object contains references things aren't practical serialize — uploaded files, or socket associated request — there's no general purpose way serialize it.

instead, should pull out , pass portions of need. example, like:

import tempfile  @app.task def location(user_id, uploaded_file_path):     # … stuff …  def tag_location(request):     tempfile.namedtemporaryfile(delete=false) f:         chunk in request.files["some_file"].chunks():             f.write(chunk)     tasks.location.delay(request.user.id, f.name)     return jsonresponse({'response': 1}) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -