summaryrefslogtreecommitdiff
path: root/docs/python.md
blob: 8094e0bfb5545eaaabb20c2233d992b0641c64ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Title: How to use libproxy in Python
Slug: snippets

# How to use libproxy in Python

```
import gi
gi.require_version('Libproxy', '1.0')
from gi.repository import Libproxy
import requests

url = 'https://github.com/libproxy/libproxy'

pf = Libproxy.ProxyFactory()
proxies = pf.get_proxies(url)

success = False
for proxy in proxies:
    response = requests.get(url) #, proxies=proxies)
    
    if response.status_code == 200:
        success = True
        break

if success:
    print(f"The requested URL {url} could be retrieved using the current setup!")
else:
    print(f"The requested URL {url} could *NOT* be retrieved using the current setup")
```