Python Code Example
A quick Python snippet to integrate into the FraudGuard.io API
This Python code performs the following steps:
- Sets the FraudGuard.io API credentials (username and password).
- Defines the IP address to query.
- Constructs the API endpoint URL.
- Encodes the credentials for basic authentication using Base64 encoding.
- Sets the Authorization header with the encoded credentials.
- Sends a GET request to the API endpoint using the requests library.
- Checks if the request was successful (status code 200) and prints the response body.
- Prints an error message if the request was unsuccessful.
import requests
import base64
# FraudGuard.io API credentials
username = 'username'
password = 'password'
# IP address to query
ip_address = '8.8.8.8'
# API endpoint
api_url = f'https://api.fraudguard.io/ip/{ip_address}'
# Encode credentials for basic authentication
auth_string = f'{username}:{password}'
encoded_auth_string = base64.b64encode(auth_string.encode()).decode()
# Set headers for the request
headers = {
'Authorization': f'Basic {encoded_auth_string}'
}
# Send GET request to the API
response = requests.get(api_url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
print(response.text)
else:
print(f"Error: {response.status_code} - {response.reason}")
Make sure to replace ‘username’ and ‘password’ with your actual API credentials.