Integrate Request with ProxyPanel

2023-09-11 14:26

CTRL+K
Thumbnail

Introduction

Requests — An Overview

The requests library is a powerful and user-friendly HTTP library for Python. It simplifies sending HTTP requests, handling responses, and managing sessions, making it ideal for web scraping and API interactions. With requests, you can easily send GET, POST, PUT, DELETE, and other types of HTTP requests, handle cookies, and manage authentication. Its simplicity and flexibility make it a popular choice for developers working on web-related tasks. For more information, visit requests documentation.

Prerequisites

Install Python from the official website.

Check if Python is installed correctly, you can use the following command in your terminal or command prompt

python --version

The output should be in the following format:

Python 3.11.2

If you receive an error or see a version number starting with 2.x, you need to download Python 3.x and follow the installation instructions to set it up

Next, create a new Python project and install the requests package

pip install requests

After installing the requests library, let's make a request to get our IP address. This can be done by sending a GET request to a service that returns your public IP. Here’s how you can do it:

import requests

response = requests.get('http://httpbin.io/ip')
print(response.json())

After running the script, it sends a GET request to http://httpbin.io/ip and retrieves your public IP address from the response. The IP address is then printed out in JSON format.

Now, we've used requests without integrating ProxyPanel proxies. Follow the next steps to configure your proxy with requests.

Configuring the Requests Package with ProxyPanel

Go to your Dashboard panel and navigate to the "My Proxy" section to view your IP information.

Click on the "Show Password" button and enter your account password to display your proxy password.

Dashboard-Credentials

To configure your ProxyPanel proxy with the requests library, use the following code:

import requests

# Proxy configuration with login and password
proxy_host = '154.128.31.247'
proxy_port = 8083
proxy_login = 'john.MyProxy-1'
proxy_password = 'proxypanel!123'
proxy = f'http://{proxy_login}:{proxy_password}@{proxy_host}:{proxy_port}'

proxies = {
    'http': proxy,
    'https': proxy
}

# Send a GET request using the proxy

response = requests.get('http://httpbin.io/ip',proxies=proxies)
print(response.json())
										

Replace username, password, proxy_address, and port with your ProxyPanel credentials and proxy details.

You will notice that the IP address with proxy configuration differs from the one without a proxy. Now you have successfully integrated the requests package with ProxyPanel.