简体   繁体   English

如何从script.py运行httpie

[英]how to run httpie from script.py

I need to send forms to a rest service from py-scripts. 我需要将表格从py脚本发送到rest服务。 i try to do it using httpie. 我尝试使用httpie做到这一点。

when i invoke run(['http', '--help']) i've got expected result. 当我调用run(['http', '--help'])我得到了预期的结果。 if i invoke run(['http', 'http://site/page']) the script is stuck and nothig happens. 如果我调用run(['http', 'http://site/page'])脚本被卡住并且nothig发生。

I also tried to place running of httpie into bash script 我也尝试将运行httpie放入bash脚本中

#!/bin/bash
http http://site/page

the result is the same as in the first case. 结果与第一种情况相同。 script is stuck. 脚本卡住了。

I use ubuntu 16.04 so I have python2 and python3 at the same time. 我使用ubuntu 16.04,因此我同时拥有python2和python3。 I run my script by python3. 我通过python3运行脚本。 mayby is there a conflict between p2 & p3 in ths case? 在这种情况下,mayby p2和p3之间是否存在冲突?

Try to include the --ignore-stdin option: 尝试包括--ignore-stdin选项:

run(['http', '--ignore-stdin', 'http://site/page'])

The --ignore-stdin option prevents HTTPie from reading data from stdin, which is usually not desirable during non-interactive invocations. --ignore-stdin选项可防止HTTPie从stdin读取数据,这在非交互式调用中通常是不希望的。

https://github.com/jkbrzt/httpie#scripting https://github.com/jkbrzt/httpie#scripting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM