2011-07-27 5 views
4

저는 파이썬에 처음으로 익숙해졌습니다. 그래서 이것이 뭔가 간단하지 않다면 미리 사과드립니다. 파이썬에서 멀티 파트 폼에 데이터를 게시하려고합니다. 스크립트는 실행되지만 게시하지 않습니다. 내가 뭘 잘못하고 있는지 모르겠다. 나는이를 호출 할 때파이썬에서 멀티 파트 양식 데이터를 게시하려고 시도하지 않습니다.

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> 

포스터/양식 데이터를으로 multipart하기 위해 데이터를 인코딩하고 여기에서 찾을 수 있습니다 : 누군가가 호기심의 Using MultipartPostHandler to POST form-data with Python

경우, 내가하려고 해요 : http://atlee.ca/software/poster/index.html

을 여기 포스터를 사용하는 코드를 발견 pdx 및 xml 밴딩 파일을 queXF (opensource 광학 마크 인식 소프트웨어) 용으로 생성 한 후 utomatically 게시하십시오. http://quexf.sourceforge.net/

+0

' 'bandingxml': '/ banding.xml'' - 위의 라인과 일치시키기 위해이 라인에서'open ('/ banding.xml ')'을 사용해야합니까? ? –

+0

나는 열 필요가있다; 그러나 나는 그것을 열어 보았을 때와 열지 않은 채 해본 적이있다. 여전히 게시하지 않습니다 – abclg

+0

값에 MAX_FILE_SIZE 및 그 값을 추가하려고 시도 했습니까? 서버가 예상 할 수 있습니다. – Gerrat

답변

1
import urllib, urllib2 
from poster.encode import multipart_encode 
from poster.streaminghttp import register_openers 

def queXF(): 
    register_openers() 
    url = "http://lilix2/trunk/admin/new.php" 
    values = {'form':open('test.pdf'), 
      'bandingxml':open('banding.xml'), 
      'desc':'description'} 
    data, headers = multipart_encode(values) 
    headers['User-Agent'] = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' 
    request = urllib2.Request(url, data, headers) 
    request.unverifiable = True 
    response = urllib2.urlopen(request) 
    the_page = response.read() 

headers['User-Agent']request.unverifiable = True이 문제를 해결 한 것 같다 추가.