gpt4 book ai didi

python - 如何在 Pycurl 中发送 DELETE 请求?

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:50 25 4
gpt4 key购买 nike

我不知道如何使用 pycurl 或 requests 在 python 中编写以下 curl 命令。

curl -X DELETE -d '{"key": "value"}' http://url/json

最佳答案

  • 你可以看看:

CURLOPT_CUSTOMREQUEST from libcurl documentation

我用来将“DELE file.txt”发送到 FTP 服务器的示例。

def delete_ftp_hash_file(self, ftp_hash_file_old):
c = pycurl.Curl()
delete_hash_file = 'DELE ' + ftp_hash_file_old
sys.stderr.write("{0:.<20} : {1} \n".format('FTP command ', delete_hash_file))
c.setopt(pycurl.URL, self.server)
c.setopt(pycurl.USERNAME, self.username)
c.setopt(pycurl.PASSWORD, self.password)
c.setopt(pycurl.VERBOSE, True)
c.setopt(pycurl.DEBUGFUNCTION, self.test)
c.setopt(pycurl.CUSTOMREQUEST, delete_hash_file)
try:
c.perform()
except Exception as e:
print e
c.close()

def test(self, debug_type, debug_msg):
if len(debug_msg) < 300:
print "debug(%d): %s" % (debug_type, debug_msg.strip())

关于python - 如何在 Pycurl 中发送 DELETE 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17075844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com