urllib2 - Could not download file using Python -
i getting error while trying download file remote source using python. explaining code below.
traceback (most recent call last): file "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) file "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 198, in _get_response "returned none instead." % (callback.__module__, view_name) valueerror: view plant.views.downloadfile didn't return httpresponse object. returned none instead.
i explaining code below.
status.html:
{% extends 'base.html' %} {% block content %} <center> <form method="post" action="{% url 'downloadfile' %}"> {% csrf_token %} <label>type file name: </label> <textarea rows="4" cols="100" name="file"> </textarea> <br> <button type="submit">download</button> </form> </center> {% endblock %}
views.py:
def downloadfile(request): """ function helps download file remote site""" if request.method == 'post': url = request.post.get('file') filename = "status" open(filename,'wb') fyl: fyl.write(urllib2.urlopen(url).read()) fyl.close() pers = user.objects.get(pk=request.session['id']) root = [] user_name = pers.uname count = 1 root.append( {'username': user_name, 'count': count }) return render(request, 'plant/home.html', {'user': root, 'count': 1})
here trying download file remote source http://www.blog.pythonlibrary.org/wpcontent/uploads/2012/06/wxdbviewer.zip
, getting error. please me resolve error.
Comments
Post a Comment