Convert curl command to pycurl

拈花ヽ惹草 提交于 2019-12-12 02:55:51

问题


im trying to convert the following curl call into pycurl , can someone help me out with that .

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"'

回答1:


Is it an option to use requests in python? It is much easier to use. Here is a small code example (not runnable):

 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'))

It is much more complicated in pycurl. Require many more lines.



来源:https://stackoverflow.com/questions/30167656/convert-curl-command-to-pycurl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!