File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # proxy-examples
2- Example code for using proxy servers in different programming languages
1+ # Proxy Examples
2+
3+ Example code for using proxy servers in different programming languages. Currently we have examples for these languages:
4+
5+ * Python
6+ * Ruby
7+
8+ ## Python Proxy Examples
9+
10+ * [ requests-proxy] ( https://github.com/proxymesh/proxy-examples/blob/main/python/requests-proxy.py )
11+ * [ requests-random-proxy] ( https://github.com/proxymesh/proxy-examples/blob/main/python/requests-random-proxy.py )
12+ * [ requests-proxy-headers] ( https://github.com/proxymesh/proxy-examples/blob/main/python/requests-proxy-headers.py )
13+ * [ urllib3-proxy-headers] ( https://github.com/proxymesh/proxy-examples/blob/main/python/urllib3-proxy-headers.py )
14+ * [ aiohttp-proxy-headers] ( https://github.com/proxymesh/proxy-examples/blob/main/python/aiohttp-proxy-headers.py )
15+ * [ httpx-proxy-headers] ( https://github.com/proxymesh/proxy-examples/blob/main/python/httpx-proxy-headers.py )
16+ * [ httpx-async-proxy-headers] ( https://github.com/proxymesh/proxy-examples/blob/main/python/httpx-async-proxy-headers.py )
17+ * [ scrapy-proxy-headers] ( https://github.com/proxymesh/proxy-examples/blob/main/python/scrapy-proxy-headers.py )
18+
19+ ## Ruby Proxy Examples
20+
21+ * requests_proxy
22+
23+ ## Contributing
24+
25+ If you have example code for another language, please share it with a Pull Request.
Original file line number Diff line number Diff line change 1+ # See https://github.com/proxymesh/python-proxy-headers
2+ from python_proxy_headers import aiohttp_proxy
3+
4+ async with aiohttp_proxy .ProxyClientSession () as session :
5+ async with session .get ('https://api.ipify.org?format=json' , proxy = "http://PROXYHOST:PORT" , proxy_headers = {'X-ProxyMesh-Country' : 'US' }) as r :
6+ await r .text ()
7+
8+ r .headers ['X-ProxyMesh-IP' ]
Original file line number Diff line number Diff line change 1+ import httpx
2+ # See https://github.com/proxymesh/python-proxy-headers
3+ from python_proxy_headers .httpx_proxy import AsyncHTTPProxyTransport
4+
5+ proxy = httpx .Proxy ('http://PROXYHOST:PORT' , headers = {'X-ProxyMesh-Country' : 'US' })
6+ transport = AsyncHTTPProxyTransport (proxy = proxy )
7+
8+ async with httpx .AsyncClient (mounts = {'http://' : transport , 'https://' : transport }) as client :
9+ r = await client .get ('https://api.ipify.org?format=json' )
10+
11+ r .headers ['X-ProxyMesh-IP' ]
Original file line number Diff line number Diff line change 1+ import httpx
2+ # See https://github.com/proxymesh/python-proxy-headers
3+ from python_proxy_headers import httpx_proxy
4+
5+ proxy = httpx .Proxy ('http://PROXYHOST:PORT' , headers = {'X-ProxyMesh-Country' : 'US' })
6+ r = httpx_proxy .get ('https://api.ipify.org?format=json' , proxy = proxy )
7+ r .headers ['X-ProxyMesh-IP' ]
Original file line number Diff line number Diff line change 1+ # See https://github.com/proxymesh/python-proxy-headers
2+ from python_proxy_headers import requests_adapter
3+
4+ proxies = {
5+ # USERNAME:PASSWORD is optional if you have IP authentication
6+ 'http' : 'http://USERNAME:PASSWORD@HOST:PORT' ,
7+ 'https' : 'http://USERNAME:PASSWORD@HOST:PORT'
8+ }
9+
10+ r = requests_adapter .get ('https://api.ipify.org?format=json' ,
11+ proxies = proxies ,
12+ proxy_headers = {'X-ProxyMesh-Country' : 'US' })
13+
14+ r .headers ['X-ProxyMesh-IP' ]
Original file line number Diff line number Diff line change 1+ # See https://github.com/proxymesh/scrapy-proxy-headers
2+
3+ # In your Scrapy `settings.py`, add the following:
4+ DOWNLOAD_HANDLERS = {
5+ "https" : "scrapy_proxy_headers.HTTP11ProxyDownloadHandler"
6+ }
7+
8+ # add to your request procesing method
9+ request .meta ["proxy_headers" ] = {"X-ProxyMesh-Country" : "US" }
10+
11+ # then when you get a response
12+ response .headers ["X-ProxyMesh-IP" ]
Original file line number Diff line number Diff line change 1+ # See https://github.com/proxymesh/python-proxy-headers
2+ from python_proxy_headers import urllib3_proxy_manager
3+
4+ proxy = urllib3_proxy_manager .ProxyHeaderManager ('http://PROXYHOST:PORT' , proxy_headers = {'X-ProxyMesh-Country' : 'US' })
5+ r = proxy .request ('GET' , 'https://api.ipify.org?format=json' )
6+ r .headers ['X-ProxyMesh-IP' ]
You can’t perform that action at this time.
0 commit comments