Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action attribute not properly handled when selecting form #230

Open
dhananjay-bajaj opened this issue Aug 29, 2018 · 1 comment
Open

Action attribute not properly handled when selecting form #230

dhananjay-bajaj opened this issue Aug 29, 2018 · 1 comment

Comments

@dhananjay-bajaj
Copy link

Hello sir,
When I select a form from browser object the target URL doesn't handle relative paths and raises an error as it can be seen in the screenshot provided below.
Error was produced when the following code was run:

import mechanicalsoup

b=mechanicalsoup.StatefulBrowser()

r=b.open('https://google.co.in')

form=b.select_form(nr=0)

form.input({'q':'parrot'})

b.submit(form)

mechanicalsoup_issue

@hemberger
Copy link
Contributor

Hi, thanks for your interest in MechanicalSoup!

I believe the issue is that you called the base class method submit instead of the preferred method submit_selected. That is, instead of

b.submit(form)

use

b.submit_selected()

However, I recognize that the base class method does not make much sense in the context of using StatefulBrowser, so I will try to make StatefulBrowser.submit a synonym for StatefulBrowser.submit_selected in an upcoming release.

hemberger added a commit to hemberger/MechanicalSoup that referenced this issue Aug 29, 2018
The obvious method to use when trying to submit a form is the `submit`
method. Unless you are following the documentation explicitly, you
may overlook the `submit_selected` method (which is really the only
correct method to use when submitting a form within a StatefulBrowser
instance).

This is demonstrated by MechanicalSoup#230, where the user got an unexpected error
because they used `submit` instead of `submit_selected`.

To adhere to the principle of least astonishment, make `submit` a
synonym for `submit_selected` (with `submit` being the primary name
and `submit_selected` being an alias for backwards compatibility).

This is a breaking change for anyone calling the base class `submit`
from a StatefulBrowser instance. It is arguable that even if the call
is made correctly, it is the "wrong" way to submit, so we should make
it more difficult to "do the wrong thing".

You can still access the base class `Browser.submit` from an instance
of `StatefulBrowser` if you need to by using the `super` builtin, e.g.

br = mechanicalsoup.StatefulBrowser()
super(StatefulBrowser, br).submit(...)
hemberger added a commit to hemberger/MechanicalSoup that referenced this issue Sep 7, 2018
This docstring note is a necessary (but probably not sufficient)
change to `Browser.submit` to prevent it from being used in an
inappropriate way from a `StatefulBrowser` instance.

See MechanicalSoup#230 and MechanicalSoup#233 for more info.
hemberger added a commit to hemberger/MechanicalSoup that referenced this issue Sep 7, 2018
This docstring note is a necessary (but probably not sufficient)
change to `Browser.submit` to prevent it from being used in an
inappropriate way from a `StatefulBrowser` instance.

See MechanicalSoup#230 and MechanicalSoup#233 for more info.
moy pushed a commit that referenced this issue Sep 7, 2018
This docstring note is a necessary (but probably not sufficient)
change to `Browser.submit` to prevent it from being used in an
inappropriate way from a `StatefulBrowser` instance.

See #230 and #233 for more info.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants