我如何在python运行curl命令
问题描述:
这是我在bash
运行命令:我如何在python运行curl命令
curl -d "username=xxxxxx" -d "password=xxxxx" <<address>> --insecure --silent
我怎样才能运行此使用Python?
答
尝试Subprocess
:
import subprocess
# ...
subprocess.call(["curl -d \"username=xxxxxx\" -d \"password=xxxxx\" https://xxxxx.com/logreg/login/ --insecure --silent" , shell=True)
我没有尝试是我写的,但基本是在这里。
检查此页面了解更多信息:Subprocess management
答
我希望你不希望明确运行curl
,但你只想得到同样的结果。
>>> import requests
>>> r = requests.get('https://example.com', auth=('user', 'pass'), verify=False)
>>> print(r.status_code)
200
http://stackoverflow.com/questions/89228/calling-an-external-command-in-python – Dobz
http://requests.readthedocs.io/en/master/ –