【问题标题】:python failed running curl XDELETE shell command [duplicate]python运行curl XDELETE shell命令失败[重复]
【发布时间】:2016-10-09 16:38:14
【问题描述】:

我不熟悉 shell,但我必须从 Python 文件运行此命令:

curl -XDELETE 'localhost:9200/event/_query?pretty' -d '{"query" : { "range" : { "int_timestamp" : { "lte" : "2016-06-09 08:55:10" } } } }'

从文件中我使用 os.popen 来执行命令。我也用 os.system 尝试过。在这两种情况下,它都会给我以下错误:

(23) Failed writing body

但是当我在 shell 中运行这个命令时,它运行良好。

我做错了什么? 感谢帮助!

编辑: 我不知道为什么,因为我没有改变什么。但现在它可以使用 os.system 而不是 os.popen。

无论如何感谢您的帮助!

【问题讨论】:

  • 你能告诉我们你的python尝试吗?无论如何,您在这里有关于错误的很好信息stackoverflow.com/questions/16703647/…
  • 在我的python文件中我使用这个命令:os.popen('curl -XDELETE \'localhost:9200/event/_query?pretty\' -d \'{"query" : { "range" : { "int_timestamp" : { "lte" : "'+stdate+'" } } } }\'')

标签: python shell python-3.x curl


【解决方案1】:

错误(23) Failed writing body 表明您在关闭文件描述符之前没有正确等待 curl 输出其数据。这可能是由于在os.popen() 之后没有调用read() 造成的

os.system 可以解决问题,但您似乎无法检索其标准输出。

【讨论】:

    猜你喜欢
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 2019-11-10
    • 1970-01-01
    • 2018-09-15
    相关资源
    最近更新 更多