Recovering from HTTPError in Mechanize

前端 未结 2 811
-上瘾入骨i
-上瘾入骨i 2021-02-08 01:40

I am writing a function for some existing python code that will be passed a Mechanize browser object as a parameter.

I fill in some details in a form in the browser, and

2条回答
  •  再見小時候
    2021-02-08 02:04

    I'm assuming that you want the submission to happen even if it takes multiple tries.

    The solution that I thought of is certainly not efficient, but it should work.

    def do_something_in_mechanize():
        <...insert your code here...>
        try:
            browser.submit()
            <...rest of your code...>
        except mechanize.HTTPError:
            do_something_in_mechanize()
    

    Basically, it'll call the function until the action is performed without HTTPErrors.

提交回复
热议问题