0

When i am doing browser.submit() ,its showing this error Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.py", line 541, in submit
    return self.open(self.click(*args, **kwds))
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.py", line 528, in click
    if not self.viewing_html():
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.py", line 443, in viewing_html
    raise BrowserStateError("not viewing any document")
mechanize._mechanize.BrowserStateError: not viewing any document

one of the reason i can think of is when i am printing browser.form then its showing

-form-urlencoded
  <TextControl(username)>
  <PasswordControl(password)>
  <HiddenControl(AUTH_STATE=08539313-ae8d-4133-ba21-247a90668ccb) (readonly)>
  <SubmitButtonControl(<None>=) (readonly)>>

may be its because its showing none in SubmitButtonControl. Can anyone suggest how can i solve this issue. In html submit button's code is login how to resolve this ?

khagler
  • 3,996
  • 29
  • 40
shailesh gupta
  • 427
  • 1
  • 5
  • 14

1 Answers1

0

The issue is you aren't getting ANY response to the browser.submit() because the SubmitButtonControl is set to None i believe. Here is what I would do first:

select the form via br.select_form(nr=WHATEVER) then use

for control in br.form.controls:
    print control.name

to see if it will print out some identifier.

Your goal is to manually assign the control a value by selecting the control like so...

browser.form['controlname']='login'
browser.urlopen(form.click())

If you can't select the control then just try the browser.urlopen(form.click()) option instead of browser.submit()

Let me know how it works out.

Amazingred
  • 1,007
  • 6
  • 14
  • when i used loop then it printed None so br.form['None']='login' didnt work. but in 2nd line it was urllib2.urlopen(form.click()) , it worked. Thanks. – shailesh gupta Mar 30 '14 at 11:18