

def get_file_from_real_browser(url):
    trial = 0
    file_from = None
    agent = random.choice(USER_AGENTS)
    referer = random.choice(REFERERS)
    wait_time = random.uniform(4, 9)
    time.sleep(wait_time)
    cookie_str = get_cookie()
    while (trial < 2):
        try:
            hdrs = {
                'User-Agent': agent,
                'Referer': referer,
                'Connection': 'keep-alive',
                'Accept-Language': 'en-us,en;q=0.5',
                'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                'Keep-Alive': '115',
                'Cookie': cookie_str,
            }
            req = urllib2.Request(url, headers=hdrs)
            print('Making a request {0}\nwith cookie:\n{1}'.format(url, cookie_str))
            file_from = urllib2.urlopen(req)
            break
        except Exception:
            trial += 1
            time.sleep(1)
    if (file_from == None):
        logger.info('Error happened while opening url {0}'.format(url))
        raise RecoDocError('Error downloading {0}'.format(url))
    elif (trial > 0):
        print('At least it was worth it')
    return file_from

dataset/ETHPy150Open bartdag/recodoc2/recodoc2/apps/docutil/commands_util.py get_file_from_real_browser/original