相关疑难解决方法(0)

如何发送POST请求?

我在网上找到了这个脚本:

import httplib, urllib
params = urllib.urlencode({'number': 12524, 'type': 'issue', 'action': 'show'})
headers = {"Content-type": "application/x-www-form-urlencoded",
            "Accept": "text/plain"}
conn = httplib.HTTPConnection("bugs.python.org")
conn.request("POST", "", params, headers)
response = conn.getresponse()
print response.status, response.reason
302 Found
data = response.read()
data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
conn.close()
Run Code Online (Sandbox Code Playgroud)

但我不明白如何使用它与PHP或params变量内的所有内容或如何使用它.试着让它发挥作用,我可以请一点帮助吗?

python urllib httplib

243
推荐指数
5
解决办法
61万
查看次数

如何使用python执行curl命令

我想在python中执行curl命令.

通常,我只需要在终端输入命令并按回车键.但是,我不知道它在python中是如何工作的.

该命令如下所示:

curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere
Run Code Online (Sandbox Code Playgroud)

有一个request.json文件要发送以获得响应.

我经常搜索并感到困惑.我试着写一段代码,虽然我无法完全理解.它没用.

import pycurl
import StringIO

response = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere')
c.setopt(c.WRITEFUNCTION, response.write)
c.setopt(c.HTTPHEADER, ['Content-Type: application/json','Accept-Charset: UTF-8'])
c.setopt(c.POSTFIELDS, '@request.json')
c.perform()
c.close()
print response.getvalue()
response.close()
Run Code Online (Sandbox Code Playgroud)

错误信息是'Parse Error'.任何人都可以告诉我如何修复它?或者如何正确地从服务器获得响应?

python curl

135
推荐指数
8
解决办法
38万
查看次数

如何使用Requests库执行HTTP DELETE请求

我正在使用请求包与toggl.com API进行交互.

我可以执行GET和POST请求:

    payload = {'some':'data'}
    headers = {'content-type': 'application/json'}
    url = "https://www.toggl.com/api/v6/" + data_description + ".json"
    response = requests.post(url, data=json.dumps(payload), headers=headers,auth=HTTPBasicAuth(toggl_token, 'api_token'))
Run Code Online (Sandbox Code Playgroud)

但我似乎无法找到执行DELETE请求的方法.这可能吗?

python django httprequest

26
推荐指数
1
解决办法
5万
查看次数

标签 统计

python ×3

curl ×1

django ×1

httplib ×1

httprequest ×1

urllib ×1