How to download an offsite file and add it to my database in Django with celery?
I'm trying to do the following with django and celery. Here is a simplified version of what I'm doing
@task
def dl_and_save_to_documents(document_pk):
document = Document.objects.get(pk=document_pk)开发者_运维知识库
f = urlopen("some/url/etc/file.pdf")
document.pdf_file=f
document.save()
No errors are returned but pdf_file remains null. Any ideas?
Thanks!
You could use a different file retrieval method. I.e. urllib.urlretrieve().
Try grab instead of urllib. It gives you nice wrapper around cURL lib, actually it's headless browser but currently w/o JS support.
精彩评论