Search code examples
pythoncurlpycurl

Convert curl command to pycurl


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

Solution

  • 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.