我使用python 2.7请求模块使用以下代码下载二进制文件,如何使此代码"自动恢复"从部分下载的文件下载.
r = requests.get(self.fileurl, stream=True, verify=False, allow_redirects=True)
if r.status_code == 200:
CHUNK_SIZE = 8192
bytes_read = 0
with open(FileSave, 'wb') as f:
itrcount=1
for chunk in r.iter_content(CHUNK_SIZE):
itrcount=itrcount+1
f.write(chunk)
bytes_read += len(chunk)
total_per = 100 * float(bytes_read)/float(long(audioSize)+long(videoSize))
self.progress_updates.emit('%d\n%s' % (total_per, 'Download Progress : ' + self.size_human(itrcount*CHUNK_SIZE) + '/' + Total_Size))
r.close()
Run Code Online (Sandbox Code Playgroud)
requests
如果可能的话,我宁愿只使用模块来实现这一点.
URIError: malformed URI sequence?
当我需要提取参数值的URL字符串中有一个%
符号时,下面的代码错误就出来了,60% - Completed
例如http://some-external-server.com/info?progress=60%%20-%20Completed
<SCRIPT type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</SCRIPT>
Run Code Online (Sandbox Code Playgroud)
我没有控制服务器,需要在我的html页面中处理输出.
我是一个PHP新手,并尝试使用以下方法向现有PHP脚本添加进度条:
$ch=curl_init() or die("ERROR|<b>Error:</b> cURL Error");
curl_setopt($ch, CURLOPT_URL, $c);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_FILE, $fp);
//####################################################//
// This is required to curl give us some progress
// if this is not set to false the progress function never
// gets called
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
// Set up the callback
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'callback');
// Big buffer less progress info/callbacks
// Small buffer more progress info/callbacks
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
//####################################################//
curl_exec($ch);
curl_close($ch);
fclose($fp);
Run Code Online (Sandbox Code Playgroud)
回调函数:
function callback($download_size, $downloaded, $upload_size, $uploaded)
{
$percent=$downloaded/$download_size;
// …
Run Code Online (Sandbox Code Playgroud) 我正在学习 Qt 并设法使用教程中的以下代码来启动外部应用程序并处理从中收到的输出:
void Dialog::on_startButton_clicked()
{
QString program = "C:/Program Files/ffmpeg/bin/ffmpeg.exe";
mTranscodingProcess = new QProcess(this);
connect(mTranscodingProcess, SIGNAL(started()), this, SLOT(processStarted()));
connect(mTranscodingProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
connect(mTranscodingProcess, SIGNAL(finished(int)), this, SLOT(encodingFinished()));
QStringList arguments;
QString input = "myfile_path_1";
QString input2 = "myfile_path_2";
arguments << "-y" << "-i" << input << "-i" << input2 << "-c" << "copy" << "output.avi" ;
qDebug() << arguments;
mTranscodingProcess->setProcessChannelMode(QProcess::MergedChannels);
mTranscodingProcess->start(program, arguments);
}
Run Code Online (Sandbox Code Playgroud)
这按预期工作,我可以捕获和处理应用程序中的输出readyReadStandardOutput()
和插槽。encodingFinished()
现在我的问题是:如何启动上述的附加作业并从每个实例接收单独的更新。
我按照这个示例键/值pyqt QComboBox,使用下面的代码将ID值存储到组合框项目.
self.combox_widget.addItem('Apples', 'Green')
indx = self.combox_widget.currentIndex()
print self.combox_widget.itemData(indx)
Run Code Online (Sandbox Code Playgroud)
但是,我开始<PyQt4.QtCore.QVariant object at 0x02AC1A70>
尝试检索DATA值(上例中的'Green').我在这里错过了什么?