Beispiel #1
0
def get_session():
    session = requests.Session()
    retries = Retry(
        total=5,
        backoff_factor=1,
        status_forcelist=[500, 502, 503, 504],
    )
    session.mount("https://", HTTPAdapter(max_retries=retries))
    return session
Beispiel #2
0
def create_session(test_ip=True):
    max_threads = multiprocessing.cpu_count()
    session = requests.Session()
    proxies = {'http': 'socks5h://'+proxy,
               'https': 'socks5h://'+proxy}
    if proxy:
        session.proxies = proxies
    session.mount(
        'https://', HTTPAdapter(pool_connections=max_threads, pool_maxsize=max_threads))
    if test_ip:
        ip = session.get('https://checkip.amazonaws.com').text.strip()
        print("Session IP: "+ip)
    return session
Beispiel #3
0
def create_session(test_ip=True):
    session = requests.Session()
    proxies = {'http': f'socks5h://{proxy}',
               'https': f'socks5h://{proxy}'}
    if proxy:
        session.proxies = proxies
        if cert:
            session.verify = cert
    max_threads2 = cpu_count()
    session.mount(
        'https://', HTTPAdapter(pool_connections=max_threads2, pool_maxsize=max_threads2))
    if test_ip:
        ip = session.get('https://checkip.amazonaws.com').text.strip()
        print("Session IP: "+ip)
    return session
Beispiel #4
0
def make_get_request(url, **kwargs):
    retry_strategy = Retry(
        total=5,
        status_forcelist=[429, 500, 502, 503, 504, 404],
        method_whitelist=["HEAD", "GET"],
        backoff_factor=0.8,
    )

    adapter = HTTPAdapter(max_retries=retry_strategy)
    session = requests.Session()
    if 'username' and 'password' in kwargs:
        session.auth = (kwargs.get('username'), kwargs.get('password'))
    data = kwargs.get('query')
    headers = kwargs.get('headers')
    session.mount("https://", adapter)
    session.mount("http://", adapter)
    # for key, value in kwargs.items():
    #print("{0} = {1}".format(key, value))
    response = session.get(url, params=data, headers=headers)
    print(response.text)
Beispiel #5
0
    def test_request_response(self):
        url = 'http://localhost:{port}/users'.format(
            port=self.mock_server_port)

        # Implement retry mechanism
        session = requests.Session()
        retry_strategy = Retry(total=5,
                               backoff_factor=1,
                               status_forcelist=[400],
                               method_whitelist=['POST'])

        adapter = HTTPAdapter(max_retries=retry_strategy)
        session.mount("http://", adapter)
        session.mount("https://", adapter)
        response = session.post(url=url)

        # Normal version
        # Send a request to the mock API server and store the response.
        response = requests.get(url)

        # Confirm that the request-response cycle completed successfully.
        print(f"response: {response}")
        assert_true(response.ok)