FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
proxy-examples/python/requests-proxy.py at main · proxymesh/proxy-examples · GitHub
proxymesh
/
proxy-examples
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
4
Code
Issues
4
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
proxy-examples
/
python
/
requests-proxy.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
32 lines (25 loc) · 1.06 KB
Breadcrumbs
proxy-examples
/
python
/
requests-proxy.py
Copy path
File metadata and controls
executable file
·
32 lines (25 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
31
32
#!/usr/bin/env python3
"""
Basic requests with proxy example.
Configuration via environment variables:
PROXY_URL - Proxy URL (required), e.g., http://user:pass@proxy:8080
TEST_URL - URL to request (default: https://api.ipify.org?format=json)
RESPONSE_HEADER - Optional header name to print from the response
Documentation: https://docs.python-requests.org/en/latest/user/advanced/#proxies
"""
import
os
import
sys
import
requests
# Get configuration from environment
proxy_url
=
os
.
environ
.
get
(
'PROXY_URL'
)
or
os
.
environ
.
get
(
'HTTPS_PROXY'
)
if
not
proxy_url
:
print
(
"Error: Set PROXY_URL environment variable"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
test_url
=
os
.
environ
.
get
(
'TEST_URL'
,
'https://api.ipify.org?format=json'
)
response_header
=
os
.
environ
.
get
(
'RESPONSE_HEADER'
)
proxies
=
{
'http'
:
proxy_url
,
'https'
:
proxy_url
}
response
=
requests
.
get
(
test_url
,
proxies
=
proxies
,
timeout
=
30
)
print
(
f"Status:
{
response
.
status_code
}
"
)
print
(
f"Body:
{
response
.
text
}
"
)
if
response_header
:
print
(
f"
{
response_header
}
:
{
response
.
headers
.
get
(
response_header
)
}
"
)
Back
|
FazBrowse Home
|
New Git URL