为了进行调试,我正在寻找PycURL中等效的curl选项“--trace [filename]”来获取PycURL发送给服务器的完整数据 .

参考PycURL File Upload (mulitpart-post) example

import pycurl

c = pycurl.Curl()
c.setopt(c.URL, 'https://httpbin.org/post')

c.setopt(c.HTTPPOST, [
    ('fileupload', (
        # upload the contents of this file
        c.FORM_FILE, __file__,
    )),
])

c.perform()
c.close()

使用 c.setopt(c.VERBOSE, True) 将改善详细程度,但它会错过发送到服务器的实际数据 .

我需要看看PycURL在发送实际文件内容之前(以及之后)发送到服务器的内容,例如curl中的“--trac”选项:

== Info: Done waiting for 100-continue
=> Send data, 149 bytes (0x95)
0000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 64 61 31 37 64 39 ----------da17d9
0020: 31 38 65 62 32 66 32 64 66 30 0d 0a 43 6f 6e 74 18eb2f2df0..Cont
0030: 65 6e 74 2d 44 69 73 70 6f 73 69 74 69 6f 6e 3a ent-Disposition:
0040: 20 66 6f 72 6d 2d 64 61 74 61 3b 20 6e 61 6d 65  form-data; name
0050: 3d 22 2f 77 77 77 2f 6c 69 62 2f 31 32 33 34 2e ="/www/lib/1234.
0060: 6d 73 69 22 3b 20 66 69 6c 65 6e 61 6d 65 3d 22 txt"; filename="
0070: 64 65 6c 6d 65 32 22 0d 0a 43 6f 6e 74 65 6e 74 debug1"..Content
0080: 2d 54 79 70 65 3a 20 74 65 78 74 2f 70 6c 61 69 -Type: text/plai
0090: 6e 0d 0a 0d 0a                                  n....
=> Send data, 16384 bytes (0x4000)