File: python.md

package info (click to toggle)
libproxy 0.5.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 728 kB
  • sloc: ansic: 3,455; sh: 228; python: 128; makefile: 37; cs: 18; perl: 6
file content (30 lines) | stat: -rw-r--r-- 658 bytes parent folder | download | duplicates (2)
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")
```