-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathintegration_example.py
33 lines (27 loc) · 1.13 KB
/
integration_example.py
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
33
import sys
import asyncio
import aiohttp
USER = "user"
PASSWORD = "password"
END_POINT = "pr.oxylabs.io:7777"
# Authorizing and passing credentials along with the proxy URL
# async def fetch():
# async with aiohttp.ClientSession() as session:
# proxy_auth = aiohttp.BasicAuth(USER, PASS)
# async with session.get("https://ip.oxylabs.io/location",
# proxy="http://pr.oxylabs.io:7777",
# proxy_auth=proxy_auth
# ) as response:
# print(await response.text())
# Passing authentication credentials in proxy URL:
async def fetch():
async with aiohttp.ClientSession() as session:
async with session.get("https://ip.oxylabs.io/location",
proxy=f"http://{USER}:{PASSWORD}@{END_POINT}"
) as response:
print(await response.text())
if __name__ == "__main__":
# Different Event Loop Policy must be loaded if you're using Windows OS
if sys.platform.startswith("win") and sys.version_info.minor >= 8:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(fetch())