Пример #1
0
    def __init__(self, email=None, password=None, cookiestring=''):
        self.email = email
        self.password = password
        self.cookiejar = StringCookieJar(cookiestring)
        self.maxreloads = 2
        self.sleeptime = 2
        self.vkhost = 'http://vkontakte.ru'
        self.vkloginhost = 'http://login.vk.com'

        handler = urllib2.HTTPCookieProcessor(self.cookiejar)
        opener = urllib2.build_opener(handler)
        urllib2.install_opener(opener)
Пример #2
0
def logoff(cookie_file, request):
    import socket
    socket.setdefaulttimeout(600)
    URL = '%s:%s' % (FB_API_URL, FB_API_PORT)
    if request.client.domain in FB_API_OTHER_URLS:
        URL = 'http://%s:%s' % (request.client.domain, FB_API_PORT)
    url = '%s/logoffUser.jsp' % URL
    cj = StringCookieJar(cookie_file)
    proxy_support = urllib2.ProxyHandler({})
    req = urllib2.Request(url, None, {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'})

    class MyHTTPRedirectHandler(urllib2.HTTPRedirectHandler):
        def http_error_302(self, req, fp, code, msg, headers):
            #log.info('Ignoring redirect %s' % (code))
            return None

        http_error_301 = http_error_303 = http_error_307 = http_error_302

    cookieprocessor = urllib2.HTTPCookieProcessor()

    opener = urllib2.build_opener(MyHTTPRedirectHandler, cookieprocessor, proxy_support)
    #opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),proxy_support)
    urllib2.install_opener(opener)
    response = None
    try:
        response = opener.open(req)
        info = response.info()
    except urllib2.URLError, e:
        if getattr(e, 'code', '')  in [301, 302]:
            pass
Пример #3
0
    def __init__(self, email=None, password=None, cookiestring=""):
        self.email = email
        self.password = password
        self.cookiejar = StringCookieJar(cookiestring)
        self.maxreloads = 2
        self.sleeptime = 2
        self.vkhost = "http://vkontakte.ru"
        self.vkloginhost = "http://login.vk.com"

        handler = urllib2.HTTPCookieProcessor(self.cookiejar)
        opener = urllib2.build_opener(handler)
        urllib2.install_opener(opener)
Пример #4
0
def init(request):
    import socket
    socket.setdefaulttimeout(10)
    URL = '%s:%s' % (FB_API_URL, FB_API_PORT)
    if request.client.domain in FB_API_OTHER_URLS:
        URL = 'http://%s:%s' % (request.client.domain, FB_API_PORT)
    url = '%s/fulfilment_test.jsp' % URL
    #url = '%s/js/mainscript.js' % API_URL
    cj = StringCookieJar()
    # ignore all proxies. put an entry in /etc/hosts and use no proxy
    proxy_support = urllib2.ProxyHandler({})
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),proxy_support)
    req = urllib2.Request(url, None, {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'})
    try:
        print datetime.now()
        response = opener.open(req)
    except urllib2.URLError, e:
        log.exception('Error initializing api %s' % repr(e))
        time.sleep(0.5) # Don't wait for more than half second
        response = opener.open(req)
Пример #5
0
class VKConnector:
    """Connector to vkontakte web site.

    Can get pages from vkontakte web site.
    Automatically log in if session is timed out.

    """
    def __init__(self, email=None, password=None, cookiestring=''):
        self.email = email
        self.password = password
        self.cookiejar = StringCookieJar(cookiestring)
        self.maxreloads = 2
        self.sleeptime = 2
        self.vkhost = 'http://vkontakte.ru'
        self.vkloginhost = 'http://login.vk.com'

        handler = urllib2.HTTPCookieProcessor(self.cookiejar)
        opener = urllib2.build_opener(handler)
        urllib2.install_opener(opener)

    def get_page(self, path):
        """Get page from vkontakte web site.

        path -- absolute path to page with slash at the beginning.

        """
        for i in xrange(self.maxreloads):
            # sleep to not be banned
            time.sleep(self.sleeptime)
            data = None
            req = urllib2.Request(self.vkhost + path, data, headers)
            handle = urllib2.urlopen(req)
            text = handle.read()
            if len(text) < 1100:
                # session timed out
                self.relogin()
            else:
                text = text.decode('cp1251')
                return text
        raise VKError('Could not get page from %s. Please, try again later.',
                      self.vkhost)

    def relogin(self):
        """Refresh session. Email and password are not needed."""
        # 1.get s-value
        data = None
        req = urllib2.Request(self.vkloginhost + '/?vk=', data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()
        match = re.search(r"action='(.*?)'.*?name='s' id='s' value='(.*?)'",
                          text, re.DOTALL)
        if match:
            # action and svalue should be something like
            # "http://vk.com/login.php?op=slogin&nonenone=1"
            # and "nonenone"
            action, svalue = match.group(1), match.group(2)
        else:
            raise VKError("s-value not returned.")

        # 2.submitting s-value
        data = urllib.urlencode({'s': svalue})
        req = urllib2.Request(action, data, headers)
        handle = urllib2.urlopen(req)
        # text should be "<html></html>"
        text = handle.read()
        # if valid s-value not returned we should login again
        if svalue == 'nonenone':
            self.login()
        # else, remixsid cookie have been received and
        # any page can be accessed
        else:
            return

    def get_cookie(self):
        """Get cookie in text format.

        Can be saved and then passed to VKConnector constructor.

        """
        return self.cookiejar.save()

    def login(self):
        """Log in to vkontakte web site."""
        # 1.visit index page
        data = None
        req = urllib2.Request(self.vkhost + '/index.php', data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()

        # 2.get s-form from http://login.vk.com/?vk=1
        data = None
        req = urllib2.Request(self.vkloginhost + '/?vk=', data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()

        # 3.submit this form (send s-value)
        data = urllib.urlencode({'s': 'nonenone'})
        req = urllib2.Request(self.vkhost + '/login.php?op=slogin&nonenone=1',
                              data, headers)
        handle = urllib2.urlopen(req)
        # text should be "<html></html>"
        text = handle.read()

        # 4. press 'submit' buttom in form first form
        data = urllib.urlencode({'op': 'a_login_attempt'})
        req = urllib2.Request(self.vkhost + '/login.php', data, headers)
        handle = urllib2.urlopen(req)
        # text shoul be 'vklogin' ?
        text = handle.read()

        # 5.actually submit login form. Get s-value.
        data = urllib.urlencode({
            'email': self.email,
            'pass': self.password,
            'expire': '',
            'vk': ''
        })
        req = urllib2.Request(self.vkloginhost + '/?act=login', data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()

        match = re.search(r"name='s' value='(.*?)'", text)
        if match:
            svalue = match.group(1)
        else:
            raise VKError("s-value not returned.")

        #6. send s-value. receive "remixsid" cookie
        data = urllib.urlencode({
            'op': 'slogin',
            'redirect': '1',
            'expire': '0',
            'to': '',
            's': svalue
        })
        req = urllib2.Request(self.vkhost + '/login.php', data, headers)
        handle = urllib2.urlopen(req)
        # text should be index page content
        text = handle.read()

        # "remixsid" received?
        if not filter(
                lambda c: c.domain == '.vkontakte.ru' and c.name == 'remixsid'
                and c.value != 'nonenone', self.cookiejar):
            raise VKError('remixsid is not returned')
Пример #6
0
def get_async_api_response(request, agent,cookie_file, api_req_id):
    URL = '%s:%s' % (FB_API_URL, FB_API_PORT)
    if request.client.domain in FB_API_OTHER_URLS:
        URL = 'http://%s:%s' % (request.client.domain, FB_API_PORT)
    url = '%s/api/%s' % (URL, 'api/')
    cj = StringCookieJar(cookie_file)
    proxy_support = urllib2.ProxyHandler({})
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),proxy_support)

    sha1 = hashlib.sha1()
    sha1.update(str(random.random()))
    data = sha1.hexdigest()
    api_key = 'AAAAB3NzaC1yc2EAAAABIwAAAQEAmj71mIXq6+cUMZ+s/2HPyAHFJh5cpflE+J2h+WBRJlLGJtb/ArvAKszaMO4q/aQpD0lB5s1yhGVNS6Hoq1GHaCSiuF71sV34I4txVfOcvLsXmvW3+8Y5hcAJoWfXPj+oeCLZAhkOhUSANHUc54syk4N8rH8nEP+ank78jvttBoTyIn54z0msO/69kY7w/Q5DcgsGKV/MpPfaVb1gL5ctoB9+2dohhLdYR8nIe1lk1iGzGVmizXJz4T4OJdi4x2ppGjOTDXAFM6hAgAxeHDoDm7DFHfxYyUwM2tzVBoTMiKohIGroZrVPak3KitBkxo/NFA3fPwaeX7ENQJ54mLVyEQ=='
    private_key = 'MIIEoAIBAAKCAQEAmj71mIXq6+cUMZ+s/2HPyAHFJh5cpflE+J2h+WBRJlLGJtb/ArvAKszaMO4q/aQpD0lB5s1yhGVNS6Hoq1GHaCSiuF71sV34I4txVfOcvLsXmvW3+8Y5hcAJoWfXPj+oeCLZAhkOhUSANHUc54syk4N8rH8nEP+ank78jvttBoTyIn54z0msO/69kY7w/Q5DcgsGKV/MpPfaVb1gL5ctoB9+2dohhLdYR8nIe1lk1iGzGVmizXJz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6KSWWxj0jW9fZjYRIckSD0KOiijI4L5yowWy028J6JPMSCPo2bsP1sGeYa6hsVuRLXlK7rPtfB6o3ZQKBgAivtq1I3hoSC+ToZroG3HmoN2PRB3syXjdJs9xnm7243Rg9YH2Qr7Knj8xhTr3nUN8q2Vk4LzNn5uW5zapZz+iiT0vbqdni18DgLWNd6NgjFeNrMyTUFk8cfAmLNAcMyYO2HQMTQTYnn5AGoC5eoQyzTFOaDtEs0TnBsDrOAsgI'
    sha2 = hashlib.sha1()
    sha2.update('%s%s%s' % (data, api_key, private_key))
    signature = sha2.hexdigest()
    session_id = get_session_id(cj)

    headers = {
            'X-FBAPI-KEY': api_key,
            'X-FBAPI-DATA': data,
            'X-FBAPI-SIGNATURE': signature,
            'X-FBAPI-AGENT': agent,
            'X-FBAPI-ID': '0',
            'tinlaHostIPAddr': socket.gethostname(),
            'tinlaSessionId': session_id,
            'tinlaOrderId': ''
            }
    count = 0
    res = None


    while count < 10: # Limiting to one retry
        count += 1
        url = url.replace('?requestId=%s' % api_req_id,'')
        url = '%s?requestId=%s' % (url,api_req_id)
        req = urllib2.Request(url, None, headers)
        log.info('API REQUEST %d-%s: %s: DATA: %s' % (api_req_id, session_id, url, ''))
        try:
            response = opener.open(req)
            json_str = response.read()
            json_str = unicode(response.read(),'utf-8','ignore')

            res =  simplejson.loads(json_str.encode('ascii','ignore'))
            log.info("API RESPONSE %d-%s:%s" % (api_req_id, session_id, res))
            if res['responseCode'] == 'AM_REQ_ID_NOT_FOUND':
                time.sleep(1)
            elif res['responseCode'] == 'GN_UNKNOWN_ERROR' and 'JSONTokener' in res['responseMessage']:
                time.sleep(1)
            else:
                log.info('Async response for request %s : %s' % (api_req_id,res))
                break
            response.close() # Close the connection
        except (httplib.IncompleteRead, httplib.BadStatusLine):
            continue
        except urllib2.URLError:
            time.sleep(1)
            continue
    if not res:
        log.error('Unable to get async response for %s' % api_req_id)
        raise APIError('Unable to get async response for %s' % api_req_id) 
    return res
Пример #7
0
def get_api_response(request, agent,path, cookie_file, method='get', params={}, post_data=None):
    import socket
    socket.setdefaulttimeout(600)
    URL = '%s:%s' % (FB_API_URL, FB_API_PORT)
    if request.client.domain in FB_API_OTHER_URLS:
        URL = 'http://%s:%s' % (request.client.domain, FB_API_PORT)
    url = '%s/api/%s' % (URL, path)
    cj = StringCookieJar(cookie_file)
    session_id = get_session_id(cj)
    proxy_support = urllib2.ProxyHandler({})
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),proxy_support)

    sha1 = hashlib.sha1()
    sha1.update(str(random.random()))
    data = sha1.hexdigest()
    #api_response = APIResponse()
    #api_response.client = 'FB'
    #api_response.save()
    api_key = 'AAAAB3NzaC1yc2EAAAABIwAAAQEAmj71mIXq6+cUMZ+s/2HPyAHFJh5cpflE+J2h+WBRJlLGJtb/ArvAKszaMO4q/aQpD0lB5s1yhGVNS6Hoq1GHaCSiuF71sV34I4txVfOcvLsXmvW3+8Y5hcAJoWfXPj+oeCLZAhkOhUSANHUc54syk4N8rH8nEP+ank78jvttBoTyIn54z0msO/69kY7w/Q5DcgsGKV/MpPfaVb1gL5ctoB9+2dohhLdYR8nIe1lk1iGzGVmizXJz4T4OJdi4x2ppGjOTDXAFM6hAgAxeHDoDm7DFHfxYyUwM2tzVBoTMiKohIGroZrVPak3KitBkxo/NFA3fPwaeX7ENQJ54mLVyEQ=='
    private_key = 'MIIEoAIBAAKCAQEAmj71mIXq6+cUMZ+s/2HPyAHFJh5cpflE+J2h+WBRJlLGJtb/ArvAKszaMO4q/aQpD0lB5s1yhGVNS6Hoq1GHaCSiuF71sV34I4txVfOcvLsXmvW3+8Y5hcAJoWfXPj+oeCLZAhkOhUSANHUc54syk4N8rH8nEP+ank78jvttBoTyIn54z0msO/69kY7w/Q5DcgsGKV/MpPfaVb1gL5ctoB9+2dohhLdYR8nIe1lk1iGzGVmizXJz4T4OJdi4x2ppGjOTDXAFM6hAgAxeHDoDm7DFHfxYyUwM2tzVBoTMiKohIGroZrVPak3KitBkxo/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3ZQKBgAivtq1I3hoSC+ToZroG3HmoN2PRB3syXjdJs9xnm7243Rg9YH2Qr7Knj8xhTr3nUN8q2Vk4LzNn5uW5zapZz+iiT0vbqdni18DgLWNd6NgjFeNrMyTUFk8cfAmLNAcMyYO2HQMTQTYnn5AGoC5eoQyzTFOaDtEs0TnBsDrOAsgI'
    sha2 = hashlib.sha1()
    sha2.update('%s%s%s' % (data, api_key, private_key))
    signature = sha2.hexdigest()
    tinla_order_ref = ''
    try:
        if 'cart_id' in request.session:
            tinla_order_ref = request.session['cart_id']
        from utils import utils
        cs = utils.get_session_obj(request)
        fbapiobj = cs.get('fbapiobj', None)
        if fbapiobj:
            if fbapiobj.add_to_cart_response:
                tinla_order_ref = fbapiobj.add_to_cart_response['items'][0]['orderId']
    except:
        pass
    if method == 'get' and params:
        #params.update({'requestId':api_response.id})
        headers = {
                'X-FBAPI-KEY': api_key,
                'X-FBAPI-DATA': data,
                'X-FBAPI-SIGNATURE': signature,
                'X-FBAPI-AGENT': agent,
                'X-FBAPI-ID': '0', #str(api_response.id),
                'tinlaHostIPAddr': socket.gethostname(),
                'tinlaSessionId': session_id,
                'tinlaOrderId': str(tinla_order_ref),
                }
        url = '%s?%s' % (url, urllib.urlencode(params))
        req = urllib2.Request(url, None, headers)

    if method == 'post' and post_data:
        #post_data.update({'requestId':api_response.id})
        log.info('Agent: %s, POST DATA: %s' % (agent,post_data))
        headers = {
                'Content-Type':'application/json; charset=UTF-8',
                'X-FBAPI-KEY': api_key,
                'X-FBAPI-DATA': data,
                'X-FBAPI-SIGNATURE': signature,
                'X-FBAPI-AGENT': agent,
                'X-FBAPI-ID': '0', #str(api_response.id),
                'tinlaHostIPAddr': socket.gethostname(),
                'tinlaSessionId': session_id,
                'tinlaOrderId': str(tinla_order_ref)
                }
        encoder = simplejson.JSONEncoder()
        data = encoder.encode(post_data)
        req = urllib2.Request(url, data, headers)

    print datetime.now()
    log.info('API REQUEST %d %s: %s: DATA: %s' % (0, session_id, url, post_data))

    try:
        try:
            response = opener.open(req)
            info = response.info()
            if info.getheaders('Set-Cookie'):
                log.info('Got new cookie for %s - %s' % 
                    (session_id, info.getheaders('Set-Cookie')))
        except urllib2.URLError, e:
            log.exception('Error doing api request: %s' % repr(e))
            import time
            time.sleep(0.5)
            try:
                response = opener.open(req)
                info = response.info()
                if info.getheaders('Set-Cookie'):
                    log.info('Got new cookie for %s - %s' % 
                        (session_id, info.getheaders('Set-Cookie')))
            except urllib2.HTTPError, error:
                raise APIError('Error reading response %s: %s' % (error.read(),
                    repr(error)))
Пример #8
0
class VKConnector:
    """Connector to vkontakte web site.

    Can get pages from vkontakte web site.
    Automatically log in if session is timed out.

    """

    def __init__(self, email=None, password=None, cookiestring=""):
        self.email = email
        self.password = password
        self.cookiejar = StringCookieJar(cookiestring)
        self.maxreloads = 2
        self.sleeptime = 2
        self.vkhost = "http://vkontakte.ru"
        self.vkloginhost = "http://login.vk.com"

        handler = urllib2.HTTPCookieProcessor(self.cookiejar)
        opener = urllib2.build_opener(handler)
        urllib2.install_opener(opener)

    def get_page(self, path):
        """Get page from vkontakte web site.

        path -- absolute path to page with slash at the beginning.

        """
        for i in xrange(self.maxreloads):
            # sleep to not be banned
            time.sleep(self.sleeptime)
            data = None
            req = urllib2.Request(self.vkhost + path, data, headers)
            handle = urllib2.urlopen(req)
            text = handle.read()
            if len(text) < 1100:
                # session timed out
                self.relogin()
            else:
                text = text.decode("cp1251")
                return text
        raise VKError("Could not get page from %s. Please, try again later.", self.vkhost)

    def relogin(self):
        """Refresh session. Email and password are not needed."""
        # 1.get s-value
        data = None
        req = urllib2.Request(self.vkloginhost + "/?vk=", data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()
        match = re.search(r"action='(.*?)'.*?name='s' id='s' value='(.*?)'", text, re.DOTALL)
        if match:
            # action and svalue should be something like
            # "http://vk.com/login.php?op=slogin&nonenone=1"
            # and "nonenone"
            action, svalue = match.group(1), match.group(2)
        else:
            raise VKError("s-value not returned.")

        # 2.submitting s-value
        data = urllib.urlencode({"s": svalue})
        req = urllib2.Request(action, data, headers)
        handle = urllib2.urlopen(req)
        # text should be "<html></html>"
        text = handle.read()
        # if valid s-value not returned we should login again
        if svalue == "nonenone":
            self.login()
        # else, remixsid cookie have been received and
        # any page can be accessed
        else:
            return

    def get_cookie(self):
        """Get cookie in text format.

        Can be saved and then passed to VKConnector constructor.

        """
        return self.cookiejar.save()

    def login(self):
        """Log in to vkontakte web site."""
        # 1.visit index page
        data = None
        req = urllib2.Request(self.vkhost + "/index.php", data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()

        # 2.get s-form from http://login.vk.com/?vk=1
        data = None
        req = urllib2.Request(self.vkloginhost + "/?vk=", data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()

        # 3.submit this form (send s-value)
        data = urllib.urlencode({"s": "nonenone"})
        req = urllib2.Request(self.vkhost + "/login.php?op=slogin&nonenone=1", data, headers)
        handle = urllib2.urlopen(req)
        # text should be "<html></html>"
        text = handle.read()

        # 4. press 'submit' buttom in form first form
        data = urllib.urlencode({"op": "a_login_attempt"})
        req = urllib2.Request(self.vkhost + "/login.php", data, headers)
        handle = urllib2.urlopen(req)
        # text shoul be 'vklogin' ?
        text = handle.read()

        # 5.actually submit login form. Get s-value.
        data = urllib.urlencode({"email": self.email, "pass": self.password, "expire": "", "vk": ""})
        req = urllib2.Request(self.vkloginhost + "/?act=login", data, headers)
        handle = urllib2.urlopen(req)
        text = handle.read()

        match = re.search(r"name='s' value='(.*?)'", text)
        if match:
            svalue = match.group(1)
        else:
            raise VKError("s-value not returned.")

        # 6. send s-value. receive "remixsid" cookie
        data = urllib.urlencode({"op": "slogin", "redirect": "1", "expire": "0", "to": "", "s": svalue})
        req = urllib2.Request(self.vkhost + "/login.php", data, headers)
        handle = urllib2.urlopen(req)
        # text should be index page content
        text = handle.read()

        # "remixsid" received?
        if not filter(
            lambda c: c.domain == ".vkontakte.ru" and c.name == "remixsid" and c.value != "nonenone", self.cookiejar
        ):
            raise VKError("remixsid is not returned")