簡體   English   中英

Python機械化307錯誤

[英]Python Mechanize 307 Error

我正在嘗試在2個不同的頁面上填寫表單,第二個頁面的表單動作是.cgi鏈接。 我可以完全填寫兩個表格,但是當我嘗試提交第二個表格時,mechanize返回307錯誤,該錯誤是由服務器生成的。

我調查了該錯誤,並說這是一個臨時重定向錯誤,但我認為機械化可以處理重定向?

有問題的代碼(我包含嘗試訪問的網址,因此代碼可運行):

from mechanize import *

counter = 0

br = Browser()
br.set_handle_redirect(HTTPRedirectHandler)
br.open('http://www.nationstates.net/page=create_nation1')
br.select_form('form')
br.form['name'] = 'faleraider' + str(counter)
br.form['currency'] = 'duobloon'
br.form['animal'] = 'parrot'
br.form['slogan'] = 'Arr, raise your new sails!'
br.form['email'] = 'falserraider' + str(counter) + '@sharklasers.com'
br.form['password'] = 'raider'
br.form['confirm_password'] = 'raider'
br.submit(name='create_nation')

br.select_form('form')
br.form['Q0'] = ['SD',]
br.form['Q1'] = ['SD',]
br.form['Q2'] = ['SD',]
br.form['Q3'] = ['SD',]
br.form['Q4'] = ['SD',]
br.form['Q5'] = ['SD',]
br.form['Q6'] = ['SD',]
br.form['Q7'] = ['SD',]
br.form.find_control('legal').selected=True
#br.set_debug_http(True)
response2 = br.submit() #error originates from here
print response2.get_data()

表格可以很好地填寫,這是服務器返回的錯誤代碼(我不知道為什么服務器將其作為錯誤返回,或者為什么機械化沒有處理它)。 請注意,我確實添加了重定向處理程序,但沒有幫助。

表單發布到的頁面是/cgi-bin/build_nation.cgi

我曾嘗試使用urllib + urllib2,Beautiful Soup和splinter,但它們都返回了相似的結果,或更糟的結果。

首次提交后,您是否不認為必須捕獲返回的內容?
我還沒有使用機械化!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM