Skip to content

Commit f0eb2bf

Browse files
committed
python requests examples
1 parent 813b38d commit f0eb2bf

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

python/requests-proxy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import requests
2+
proxies = {
3+
# USERNAME:PASSWORD is optional if you have IP authentication
4+
'http': 'http://USERNAME:PASSWORD@HOST:PORT',
5+
'https': 'http://USERNAME:PASSWORD@HOST:PORT'
6+
}
7+
response = requests.get('http://example.com', proxies=proxies)

python/requests-random-proxy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
import requests
3+
proxy_choices = ['HOST1:PORT', 'HOST2:PORT']
4+
proxy = random.choice(proxy_choices)
5+
proxies = {
6+
'http': f'http://{proxy}',
7+
'https': f'http://{proxy}'
8+
}
9+
response = requests.get('http://example.com', proxies=proxies)

0 commit comments

Comments
 (0)