Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- from dotenv import dotenv_values
- def test_get_request(username,password):
- url = "http://api.your-url.com"
- response = requests.get(url,verify=False, auth=(username,password))
- # If the request was successful, response.status_code will be 200
- print(f"Status code: {response.status_code}")
- # Assuming that the response is JSON, you can convert the response to a Python dictionary using .json()
- if response.status_code == 200:
- data = response.json()
- obj = json.loads(data)
- json_formatted_str = json.dumps(obj, indent=0)
- print(json_formatted_str)
- #print(f"Content:\n{data}")
- else:
- print(f"Response content is not printed because the request was not successful.")
- # Check if the request was successful
- if response.status_code == 200:
- return True
- else:
- return False
- config = dotenv_values(".env")
- # Test GET API
- test_result = test_get_request(config['username'],config['password'])
- if test_result:
- print("The GET request to the API was successful.")
- else:
- print("The GET request to the API was not successful.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement