将curl命令转换为pycurl [英] Convert curl command to pycurl

查看:90
本文介绍了将curl命令转换为pycurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将以下curl调用转换为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"'

推荐答案

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

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

在pycurl中它要复杂得多.需要更多行.

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

这篇关于将curl命令转换为pycurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆