How to use the micawber.exceptions.ProviderException function in micawber

To help you get started, we’ve selected a few micawber 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 coleifer / micawber / micawber / providers.py View on Github external
def request(self, url, **extra_params):
        encoded_params = self.encode_params(url, **extra_params)

        endpoint_url = self.endpoint
        if '?' in endpoint_url:
            endpoint_url = '%s&%s' % (endpoint_url.rstrip('&'), encoded_params)
        else:
            endpoint_url = '%s?%s' % (endpoint_url, encoded_params)

        response = self.fetch(endpoint_url)
        if response:
            return self.handle_response(response, url)
        else:
            raise ProviderException('Error fetching "%s"' % endpoint_url)
github coleifer / micawber / micawber / exceptions.py View on Github external
class ProviderException(Exception):
    pass

class ProviderNotFoundException(ProviderException):
    pass

class InvalidResponseException(ProviderException):
    pass
github coleifer / micawber / micawber / exceptions.py View on Github external
class ProviderException(Exception):
    pass

class ProviderNotFoundException(ProviderException):
    pass

class InvalidResponseException(ProviderException):
    pass
github divio / djangocms-oembed / djangocms_oembed / models.py View on Github external
extra = {}
        if self.width:
            extra['maxwidth'] = self.width
        if self.height:
            extra['maxheight'] = self.height
        extra['autoplay'] = self.autoplay
        extra['rel'] = self.show_related
        extra['loop'] = self.loop
        extra['title'] = False  # Vimeo
        extra['byline'] = False  # Vimeo
        extra['portrait'] = False  # Vimeo
        try:
            data = providers.request(self.oembed_url, **extra)
        except ProviderNotFoundException, e:
            raise ValidationError(e.message)
        except ProviderException, e:
            raise ValidationError(e.message)
        if not data['type'] == 'video':
            raise ValidationError('This must be an url for a video. The "%(type)s" type is not supported.' % {'type': data['type']},)
        self.type = data.get('type', '')
        self.provider = data.get('provider_name', '')
        html = data.get('html', '')
        if 'provider_name' in data and self.provider in ['YouTube', 'Vimeo']:
            # dirty special handling of youtube and vimeo.
            # they ignore these parameters over oembed... so we use our own template to render them.
            iframe_html = PyQuery(html)
            url = iframe_html.attr('src')
            params = {
                'autoplay': int(self.autoplay),
                'loop': int(self.loop),
                'rel': int(self.show_related),
                'showinfo': 0,  # YouTube
github django-fluent / django-fluent-contents / fluent_contents / plugins / oembeditem / management / commands / debug_oembed.py View on Github external
def handle(self, *args, **options):
        if not args:
            raise CommandError("Missing URL parameter")

        for url in args:
            try:
                data = get_oembed_data(url)
            except ProviderNotFoundException:
                self.stderr.write("* No OEmbed provider found for '{0}'!\n".format(url))
            except ProviderException as e:
                # Real urllib2 exception is sadly hidden by micawber.
                self.stderr.write("* {0}\n".format(e))
            else:
                self.stdout.write("* OEmbed data for '{0}':\n".format(url))

                for key in sorted(data.keys()):
                    self.stdout.write("  - {0}: {1}\n".format(key, pformat(data[key])))
github coleifer / micawber / micawber / parsers.py View on Github external
def extract(text, providers, **params):
    all_urls = set()
    urls = []
    extracted_urls = {}

    for url in re.findall(url_re, text):
        if url in all_urls:
            continue

        all_urls.add(url)
        urls.append(url)
        try:
            extracted_urls[url] = providers.request(url, **params)
        except ProviderException:
            pass

    return urls, extracted_urls