How to use the pylast.MalformedResponseError function in pylast

To help you get started, we’ve selected a few pylast 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 jaedb / spotmop / mopidy_spotmop / frontend.py View on Github external
def on_start(self):
        
        logger.info('Starting Spotmop '+self.version)
        
        # try and start a pusher server
        port = str(self.config['spotmop']['pusherport'])
        try:
            self.pusher = tornado.web.Application([( '/pusher', pusher.PusherWebsocketHandler, { 'frontend': self } )])
            self.pusher.listen(port)
            logger.info('Pusher server running at [0.0.0.0]:'+port)
            
        except( pylast.NetworkError, pylast.MalformedResponseError, pylast.WSError ) as e:
            logger.error('Error starting Pusher: %s', e)
            self.stop()
        
        # get a fresh spotify authentication token and store for future use
        self.refresh_spotify_token()
github asermax / lastfm_extension / pylast.py View on Github external
def _check_response_for_errors(self, response):
        """Checks the response for errors and raises one if any exists."""
        
        try:
            doc = minidom.parseString(_string(response))
        except Exception as e:
            raise MalformedResponseError(self.network, e)
            
        e = doc.getElementsByTagName('lfm')[0]
        
        if e.getAttribute('status') != "ok":
            e = doc.getElementsByTagName('error')[0]
            status = e.getAttribute('code')
            details = e.firstChild.data.strip()
            raise WSError(self.network, status, details)
github erik / lastcast / lastcast / __init__.py View on Github external
def _log_scrobble(self, track_meta):
        ''' Scrobble current track to user's profile. '''

        click.echo('Scrobbling: {artist} - {title} [{album}]'.format(**track_meta))

        for scrobbler in self.scrobblers:
            try:
                scrobbler.scrobble(timestamp=int(time.time()), **track_meta)
            except (pylast.NetworkError, pylast.MalformedResponseError) as exc:
                click.echo('Failed to scrobble to {}: {}'.format(
                    scrobbler.name, str(exc)))

                logger.info('_log_scrobble(%s) failed', scrobbler.name,
                            exc_info=True)

        self.last_scrobbled = track_meta
github mps-youtube / mps-youtube / mps_youtube / commands / lastfm.py View on Github external
def set_now_playing(artist, track):
    """ Set the current track as "now playing" on the user's Last.fm account """
    if not g.lastfm_network:
        return
    try:
        g.lastfm_network.update_now_playing(artist=artist, title=track)
    except (pylast.WSError, pylast.MalformedResponseError, pylast.NetworkError):
        return
github maxexcloo / LastDown / pylast.py View on Github external
def _check_response_for_errors(self, response):
        """Checks the response for errors and raises one if any exists."""
        
        try:
            doc = minidom.parseString(_string(response))
        except Exception as e:
            raise MalformedResponseError(self.network, e)
            
        e = doc.getElementsByTagName('lfm')[0]
        
        if e.getAttribute('status') != "ok":
            e = doc.getElementsByTagName('error')[0]
            status = e.getAttribute('code')
            details = e.firstChild.data.strip()
            raise WSError(self.network, status, details)
github maxexcloo / LastDown / pylast.py View on Github external
body=data, headers=headers)
            except Exception as e:
                raise NetworkError(self.network, e)
                
        else:
            conn = HTTPConnection(host=HOST_NAME)
            
            try:
                conn.request(method='POST', url=HOST_SUBDIR, body=data, headers=headers)
            except Exception as e:
                raise NetworkError(self.network, e)
        
        try:
            response_text = _unicode(conn.getresponse().read())
        except Exception as e:
            raise MalformedResponseError(self.network, e)
        
        self._check_response_for_errors(response_text)
        return response_text
github beetbox / beets / beetsplug / lastgenre / __init__.py View on Github external
import yaml

from beets import plugins
from beets import ui
from beets.util import normpath, plurality
from beets import config
from beets import library

log = logging.getLogger('beets')

LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY)
C14N_TREE = os.path.join(os.path.dirname(__file__), 'genres-tree.yaml')

PYLAST_EXCEPTIONS = (
    pylast.WSError,
    pylast.MalformedResponseError,
    pylast.NetworkError,
)


# Core genre identification routine.

def _tags_for(obj):
    """Given a pylast entity (album or track), returns a list of
    tag names for that entity. Returns an empty list if the entity is
    not found or another error occurs.
    """
    try:
        res = obj.get_top_tags()
    except PYLAST_EXCEPTIONS as exc:
        log.debug(u'last.fm error: %s' % unicode(exc))
        return []
github asermax / lastfm_extension / pylast.py View on Github external
body=data, headers=headers)
            except Exception as e:
                raise NetworkError(self.network, e)
                
        else:
            conn = HTTPConnection(host=HOST_NAME)
            
            try:
                conn.request(method='POST', url=HOST_SUBDIR, body=data, headers=headers)
            except Exception as e:
                raise NetworkError(self.network, e)
        
        try:
            response_text = _unicode(conn.getresponse().read())
        except Exception as e:
            raise MalformedResponseError(self.network, e)
        
        self._check_response_for_errors(response_text)
        return response_text