django错误使用curl下载CURLOPT_RESUME_FROM_LARGE

时间:2013-07-24 03:56:11

标签: django libcurl

我使用django,仅用于下载文件服务器。 并使用curl在客户端下载文件。 当我为Resume broken transfer添加CURLOPT_RESUME_FROM_LARGE时,错误来了。 我不知道是服务器错误还是客户端错误 我的客户端下载代码:

    FILE* ptmpfile = fopen((m_download_filepath_pre+tmpfilename).c_str(), "ab+");
    fseek(ptmpfile, 0L, SEEK_END);
    int currentsize = ftell(ptmpfile);

    curl_easy_setopt(curl, CURLOPT_FILE, ptmpfile);
    curl_easy_setopt(curl, CURLOPT_HEADER ,0);
    curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT,60);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS ,0);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION ,my_progress_func);
    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA ,sDownload);
    curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, currentsize);

myserver错误:

Exception happened during processing of request from ('127.0.0.1', 50232)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 582, in process_request_thread
    self.finish_request(request, client_address)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/servers/basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

感谢~~

修正:) 客户端错误CURLOPT_RESUME_FROM_LARGE必须获取curl_off_t参数。

curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)currentsize);

或使用

curl_easy_setopt(curl, CURLOPT_RESUME_FROM, currentsize);

但谁知道CURLOPT_RESUME_FROM_LARGE和CURLOPT_RESUME_FROM之间有什么不同?

0 个答案:

没有答案