将 curl 命令转换为 pycurl

Convert curl command to pycurl

我正在尝试将以下 curl 调用转换为 pycurl,谁能帮我解决这个问题。

curl --request 'POST' 'https://api.twitter.com/1.1/mutes/users/create.json' --data 'screen_name=fails' 
--header 'Authorization: OAuth oauth_consumer_key="mZRm27WsyGa8PRxcDC", oauth_nonce="5d10f384e1a8f176ca0a74b3dd2", oauth_signature="vYY%2BbHfXv1PTfc0MbY9jcLU%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1431346223", oauth_token="17718839-bewY3FfcV7vBPSd3pBOzscoxGmFeU", oauth_version="1.0"'

是否可以选择在 python 中使用 requests?它更容易使用。这是一个小代码示例(不可运行):

 import requests
 import json

 myurl= 'https://api.twitter.com/1.1/mutes/users/create.json'
 to_post = {"label":"value"}
 to_post = json.dumps(to_post)  #Convert to json if that is the correct content-type
 r = requests.post(myurl,data = to_post , auth = ('username', 'password'))

pycurl就复杂多了。需要更多行。