Python 无法使用httplib2提交没有文件的多部分表单

Python 无法使用httplib2提交没有文件的多部分表单,python,web-scraping,python-2.7,urllib2,httplib2,Python,Web Scraping,Python 2.7,Urllib2,Httplib2,我需要编写一个脚本,通过选择“蛋白质结构(转到步骤2b)”,然后在名为“pdbId”的文本字段中输入一些值,而无需上传任何文件,即可在自动提交表单。 我写了下面的脚本,但它给了我相同的页面没有任何提交发生。怎么了 import httplib2 http = httplib2.Http() url = 'http://iedb.ebi.ac.uk/tools/ElliPro/iedb_input' body = { 'pdbFile' : '', 'protein_type':'s

我需要编写一个脚本,通过选择“蛋白质结构(转到步骤2b)”,然后在名为“pdbId”的文本字段中输入一些值,而无需上传任何文件,即可在自动提交表单。 我写了下面的脚本,但它给了我相同的页面没有任何提交发生。怎么了

 import httplib2

 http = httplib2.Http()

url = 'http://iedb.ebi.ac.uk/tools/ElliPro/iedb_input'   
body = { 'pdbFile' : '', 'protein_type':'structure','pdbId':'5LYM' }
headers = {'Content-type': 'application/x-www-form-urlencoded','User-Agent':'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'}
response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
print content

我最终使用了mechanize,它成功了

 from mechanize import Browser, _http
 br = Browser()
 br.set_handle_robots(False)
 br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

 br.open('http://iedb.ebi.ac.uk/tools/ElliPro/iedb_input')
 br.select_form(name='predictionForm')
 br.form['protein_type'] = ['structure',]
 br.form['pdbId'] = '5LYM'
 submit_response = br.submit(name='Submit', label='Submit')
 print submit_response.read()

我最终使用了mechanize,它成功了

 from mechanize import Browser, _http
 br = Browser()
 br.set_handle_robots(False)
 br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

 br.open('http://iedb.ebi.ac.uk/tools/ElliPro/iedb_input')
 br.select_form(name='predictionForm')
 br.form['protein_type'] = ['structure',]
 br.form['pdbId'] = '5LYM'
 submit_response = br.submit(name='Submit', label='Submit')
 print submit_response.read()