2016-09-20 189 views
-2

这是我在bash运行命令:我如何在python运行curl命令

curl -d "username=xxxxxx" -d "password=xxxxx" <<address>> --insecure --silent 

我怎样才能运行此使用Python?

+3

http://stackoverflow.com/questions/89228/calling-an-external-command-in-python – Dobz

+1

http://requests.readthedocs.io/en/master/ –

回答

0

尝试Subprocess

import subprocess 
# ... 

subprocess.call(["curl -d \"username=xxxxxx\" -d \"password=xxxxx\" https://xxxxx.com/logreg/login/ --insecure --silent" , shell=True) 

我没有尝试是我写的,但基本是在这里。

检查此页面了解更多信息:Subprocess management

0

我希望你不希望明确运行curl,但你只想得到同样的结果。

>>> import requests 
>>> r = requests.get('https://example.com', auth=('user', 'pass'), verify=False) 
>>> print(r.status_code) 
200