python requests use proxy code example

Example 1: python requests get proxy

import requests

proxies = { "http": "http://10.10.10.10:8000",
           "https": "https://10.10.10.10:8000"
}
r = requests.get("http://toscrape.com", proxies=proxies)

Example 2: python requests use proxy

import requests

proxies = {
  "http": "http://10.10.1.10:3128",
  "https": "https://10.10.1.10:1080",
}

requests.get("http://example.org", proxies=proxies)

Example 3: requests sessions

s = requests.Session()

s.get('https://httpbin.org/cookies/set/sessioncookie/123456789')
r = s.get('https://httpbin.org/cookies')

print(r.text)
# '{"cookies": {"sessioncookie": "123456789"}}'

Example 4: post request with proxy python

from proxy_requests import ProxyRequests

r = ProxyRequests('url here')
r.set_headers({'name': 'rootVIII', 'secret_message': '7Yufs9KIfj33d'})
r.post_with_headers({'key1': 'value1', 'key2': 'value2'})