requests.codes.forbidden

Here are the examples of the python api requests.codes.forbidden taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: EDMarketConnector Source File: companion.py
Function: query
    def query(self):
        if self.state == Session.STATE_NONE:
            raise Exception('General error')	# Shouldn't happen - don't bother localizing
        elif self.state == Session.STATE_INIT:
            self.login()
        elif self.state == Session.STATE_AUTH:
            raise VerificationRequired()
        try:
            r = self.session.get(URL_QUERY, timeout=timeout)
        except:
            if __debug__: print_exc()
            raise ServerError()

        if r.status_code == requests.codes.forbidden or r.url == URL_LOGIN:
            # Start again - maybe our session cookie expired?
            self.state = Session.STATE_INIT
            return self.query()

        if r.status_code != requests.codes.ok:
            self.dump(r)
            raise ServerError()

        try:
            data = r.json()
        except:
            self.dump(r)
            raise ServerError()

        return data

Example 2

Project: vidscraper Source File: test_youtube.py
Function: test_forbidden
    def test_forbidden(self):
        expected_data = {'is_embeddable': False}
        response = self.get_response('', code=requests.codes.forbidden)
        data = self.loader.get_video_data(response)
        self.assertDictEqual(data, expected_data)

Example 3

Project: vidscraper Source File: test_youtube.py
    def test_get_video_data__forbidden(self):
        expected_data = {'is_embeddable': False}
        response = self.get_response('', code=requests.codes.forbidden)
        data = self.loader.get_video_data(response)
        self.assertDictEqual(data, expected_data)