【问题标题】:download a file with curl command using Popen subprocess使用 Popen 子进程使用 curl 命令下载文件
【发布时间】:2019-10-15 06:05:31
【问题描述】:

我正在使用 curl 命令下载文件并打开子进程来运行该命令。 我想把下载的限制速率控制在50mps。

当我在终端中运行低于 commad 时,它工作正常。

curl -o down.tar.gz --limit-rate 50M http://localhost:5000/download

但是当我运行 Popen 以在 pycharm 中运行该命令时,如下所示,

Popen(['curl', '-o', 'down.tar.gz','--limit-rate 50M', 'http://localhost:5000/download'])

然后它给我如下所示的错误,

curl: option --limit-rate 50M: is unknown
curl: try 'curl --help' or 'curl --manual' for more information

如何在 Popen 中使用 curl 限制速率?

【问题讨论】:

    标签: python-3.x curl subprocess popen


    【解决方案1】:

    当使用列表调用Popen 时,参数不会进一步拆分。因此,您的代码将整个--limit-rate 50M 作为单个参数传递给curl。

    您需要像这样在命令令牌列表中拆分选项和选项值:

    Popen(['curl', '-o', 'down.tar.gz','--limit-rate', '50M', 'http://localhost:5000/download'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 2022-10-15
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      相关资源
      最近更新 更多