import pycurl url = "http://www.xxxxx.com/upload.php"
field = "uploadFile"
file = "/home/rare/tmp/a.py"
c = pycurl.Curl() c.setopt(c.POST, 1) c.setopt(c.URL, url) c.setopt(c.HTTPPOST, [(field, (c.FORM_FILE, file))]) #c.setopt(c.VERBOSE, 1) c.perform() c.close()
其中url和field分別替換爲提交表單中action對應的腳本地址和file類型的input標籤的name值
file是需要上傳的文件路徑,需要注意在windows下反斜槓必須轉移,例如"c://a//b//c.txt"