[問題] 關於在http上傳檔案

看板Python作者 (Minimi)時間15年前 (2010/05/11 21:28), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
最近我用python作一些操作網頁介面的事情 說的明確一點就是丟一些http get/post request,然後讀取回應 主要用的是urllib,沒有特別理由,純粹因為剛好找到可行的範例 但是,我在上傳檔案的時候遇到了問題 我的方法是將檔案用read的方式倒出來,用post的方式加在檔案後面,urlopen丟出去 params = urllib.urlencode({'sid':sid, 'count':random.random()}) with open(file, "r") as f: tempfile = f.read() data = urllib.urlencode({'file':tempfile}) f = urllib.urlopen("http://"+IP+":8080/Request.cgi?%s" % params, data) 我覺得出問題的地方可能在於檔案附加的方式或是post的參數給錯 抓參數名的方法是用firebug查看 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.169.210.171 ※ 編輯: hl4 來自: 118.169.210.171 (05/11 21:36)
文章代碼(AID): #1BwLjjeo (Python)
文章代碼(AID): #1BwLjjeo (Python)