def __init__(self): # noinspection SpellCheckingInspection opensubtitles_ua = b'VkxzdWIgMC4xMC4y' self.ua = base64.b64decode(opensubtitles_ua).decode() self.opensubtitles_api_url = 'http://api.opensubtitles.org/xml-rpc' self.opensubtitles_lang = 'en' self.token = None self.xmlrpc_transport = Transport() self.xmlrpc_transport.user_agent = self.ua self.xmlrpc = ServerProxy(self.opensubtitles_api_url, allow_none=True, transport=self.xmlrpc_transport)
def __init__(self, user_agent, server='http://api.opensubtitles.org/xml-rpc', language='eng'): self.server = server self.language = language trans = Transport() trans.user_agent = user_agent self._rpc = ServerProxy(self.server, allow_none=True, transport=trans) login_response = self._rpc.LogIn('', '', language, user_agent) assert_status(login_response) self._token = login_response.get('token')
def login(): transport = Transport() transport.user_agent = constants.USER_AGENT_OPENSUBS xmlrpc = ServerProxy(constants.OPENSUBTITLES_URL, allow_none=True, transport=transport) try: data = xmlrpc.LogIn(constants.USERNAME, constants.PASSWORD, constants.LANGUAGE, constants.USER_AGENT_OPENSUBS) except: logging.warning( "Error occured while establishing connection to opensubtitles...") return None, None if '200' == data.get('status').split()[0]: logging.info("Got token from opensubtitles") return data.get('token'), xmlrpc else: logging.warning( "Error occured while getting opensubtitles token. Returned status as " + data.get('status').split()[0]) return None
import os import sys import json import requests from zipfile import ZipFile import logging from xmlrpc.client import ServerProxy, Transport logger = logging.getLogger() OPENSUBTITLES_SERVER = 'http://api.opensubtitles.org/xml-rpc' LANGUAGE = 'en' USER_AGENT = "TemporaryUserAgent" CHUNK_SIZE = 128 t = Transport() t.user_agent = USER_AGENT xmlrpc = ServerProxy(OPENSUBTITLES_SERVER,transport=t,allow_none=True) def login(uname,pwd): try: token = xmlrpc.LogIn(uname,pwd,LANGUAGE,USER_AGENT) if '200 OK' in token['status']: return token['token'] else: return None except Exception as e: print('Login Error : {error} '.format(error = str(e)))
"414": SubAuthError, "415": SubAuthError, "416": SubUploadError, "429": SubServerError, "503": SubServerError, "506": SubServerError, "520": SubServerError, } _API_PROTOCOL_ERR_MAP = { 503: "503 Service Unavailable", 506: "506 Server under maintenance", 520: "520 Unknown internal error", } _client = ServerProxy(API_BASE, allow_none=True, transport=Transport()) # TODO: give a way to let lib user to set `TIMEOUT`? def request(endpoint, token, *params): """ Function to allow for robust and reusable calls to the XMLRPC API. `endpoint` is the `Endpoint` that you want to use from the opensubtitles API. `token` is the auth token that is used for any user-authenticated calls. `*params` are any additional parameters to pass to the API. Note: Retrying with exponential backoff and exposing appropriate errors are all handled automatically. """ TIMEOUT = 15 DELAY_FACTOR = 2 current_delay = 1.5
from nestegg import NesteggException from requests import get, head from xmlrpc.client import ServerProxy, Transport pypi_client = ServerProxy("https://pypi.python.org/pypi", Transport()) def get_real_pkg_name(pkg_name): r = head('https://pypi.python.org/simple/{0}/'.format(pkg_name)) if r.status_code == 200: return pkg_name if 300 <= r.status_code <= 399: location = r.headers["location"] if location.startswith("/simple/"): return location.split("/")[-1] else: raise NesteggException( "Unexpected redirect from pypi: {}".format(location)) raise NesteggException( "Unable to get real package name for {} from pypi".format(pkg_name)) def get_package_details(pkg_name): real_pkg_name = get_real_pkg_name(pkg_name) releases = pypi_client.package_releases(real_pkg_name, True) print(releases) for release in releases: urls = pypi_client.release_urls(real_pkg_name, release) print(release, urls)