私はPythonにはかなり新しいので、これが何か簡単でない場合は事前にお詫びします。私はPythonでマルチパートフォームにデータを投稿しようとしています。スクリプトは実行されますが、投稿はされません。私は何が間違っているのか分かりません。Pythonでマルチパートのフォームデータを投稿しようとしても投稿されません
import urllib, urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
def toqueXF():
register_openers()
url = "http://localhost/trunk/admin/new.php"
values = {'form':open('/test.pdf'),
'bandingxml':open('/banding.xml'),
'desc':'description'}
data, headers = multipart_encode(values)
request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
the_page = response.read()
print the_page
私はこれを呼び出すと、私は「urllib2.urlopen(URL)」を実行し、任意のデータを投稿していなかったかのように、印刷は、私のページのHTMLを与える:
<form enctype="multipart/form-data" action="" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /></p>
<p>Select PDF file to create form from: <input name="form" type="file" /></p>
<p>(Optional): Select banding XML file: <input name="bandingxml" type="file" /></p>
<p>Enter description of form: <input name="desc" type="text"/><br/></p>
<p><input type="submit" value="Upload form" /></p>
</form>
ポスターを/フォームデータをマルチパートデータをエンコードすることであり、ここで見つけることができます:http://atlee.ca/software/poster/index.html
私はコードがここにポスターを使用することが分かっ:Using MultipartPostHandler to POST form-data with Python
誰でも好奇心旺盛だ場合は、私がしようとしていますpdfとxmlバンディングファイルがutX(opensource光学式マーク認識ソフトウェア)のために生成された後、utomaticallyポストする。 headers['User-Agent']
とrequest.unverifiable = True
それを修正しているようだの追加http://quexf.sourceforge.net/
''bandingxml': '/ banding.xml'' - 上記の行と一致するようにこの行に' open('/banding.xml ') 'を使用する必要がありますか? ? –
私はオープンが必要です。しかし、私はそれを試してみた。まだ投稿していません – abclg
あなたの値にMAX_FILE_SIZEとその値を追加してみましたか?サーバーがそれを期待している可能性があります。 – Gerrat