File size: 2,025 Bytes
4e99679
 
 
 
 
 
a7539f2
4e99679
 
 
a7539f2
 
 
4e99679
a7539f2
4e99679
a7539f2
 
 
 
 
 
 
 
4e99679
a7539f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e99679
 
bf4b341
 
 
 
 
341d820
bf4b341
 
 
 
 
 
4e99679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341d820
4e99679
 
 
 
 
 
 
a7539f2
4e99679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Generic code to make api requests using python requests library: frame 



import requests

from urllib.parse import urljoin, urlencode

# Define the base URL
#BASE_URL = 'http://127.0.0.1:5000/'
import httpx

BASE_URL = 'https://d9c5-134-28-45-21.ngrok-free.app/'

async def make_get_request(endpoint, params):

    async with httpx.AsyncClient() as client:
        try:
            response = await client.get(urljoin(BASE_URL, endpoint), params=params)
            print(response.url)
            response.raise_for_status()  # Check if the response is successful
        except httpx.HTTPError as e:
            print(f"Request failed: {e}")
            return None

    print(response)
    return response

async def make_post_request(endpoint, params, data=None):
    if data is None:
        return None
    
    async with httpx.AsyncClient() as client:
        try:
            response = await client.post(urljoin(BASE_URL, endpoint), params=params, data=data)
            response.raise_for_status()  # Check if the response is successful
        except httpx.HTTPError as e:
            print(f"Request failed: {e}")
            return None
    return response


"""
def make_get_request(endpoint,params):

    try: 
        # Make a GET request to the endpoint
        response = requests.get(
            url = f'{BASE_URL}{endpoint}',
            params=params, 
            verify=True
        )
        print(response.url)
        # Check if the response is successful
    except requests.RequestException as e:
        print(f"Request failed: {e}")
        return None
    return response
    

# Make a POST request to the endpoint

def make_post_request(endpoint,params,data=None):
    if data is None:
        return 
    
    
    # Make a POST request to the endpoint
    response = requests.post(
        url=BASE_URL + endpoint,
        params=params,
        data=data,
        verify=True
    )

    # Check if the response is successful
    
    # Return the error
    return response

"""