Skip to Content
Mastering Python for Networking and Security
book

Mastering Python for Networking and Security

by José Manuel Ortega
September 2018
Intermediate to advanced
426 pages
10h 46m
English
Packt Publishing
Content preview from Mastering Python for Networking and Security

Making Proxy Requests

An interesting feature offered by the requests module is the possibility to make requests through a proxy or intermediate machine between our internal network and the external network.

A proxy is defined in the following way:

>>> proxy = {"protocol":"ip:port", ...}

To make a request through a proxy, the proxies attribute of the get method is used:

>>> response = requests.get(url,headers=headers,proxies=proxy)

The proxy parameter must be passed in the form of a dictionary, that is, you have to create a dictionary type where we specify the protocol with the IP address and the port where the proxy is listening:

import requestshttp_proxy = "http://<ip_address>:<port>"proxy_dictionary = { "http" : http_proxy}requests.get("http://example.org", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Networking and Security - Second Edition

Mastering Python for Networking and Security - Second Edition

José Manuel Ortega
Python for Cybersecurity

Python for Cybersecurity

Howard E. Poston, III

Publisher Resources

ISBN: 9781788992510Supplemental Content