2015-05-11 100 views
0

即時嘗試將下面的curl調用轉換爲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"' 
+0

你到目前爲止嘗試過什麼?在我看來你的工作流程是:閱讀[pycurl](https://pypi.python.org/pypi/pycurl)API並翻譯[curl](http://curl.haxx.se/)CLI參數/選項。 PS:幾乎沒有**一個「魔法」「將xyz轉換成abc」按鈕! –

+0

您是否嘗試過[請求](https://pypi.python.org/pypi/requests)庫? *人類的HTTP * –

回答

4

是否可以在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中的代碼更加複雜。需要更多的線路。