-
Notifications
You must be signed in to change notification settings - Fork 3
/
sample.py
45 lines (32 loc) · 892 Bytes
/
sample.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
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
import asyncio
import aiohttp
import requests
import anticens
def test_requests():
try:
r = requests.get('https://www.pixiv.net/')
print(r.status_code)
# print(r.text)
except:
print('Blocked!')
async def test_aiohttp():
try:
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with session.get('https://www.pixiv.net/') as r:
print(r.status)
# print(await r.text())
except:
print('Blocked!')
def main():
loop = asyncio.get_event_loop()
anticens.add_hosts(['www.pixiv.net'])
anticens.enable()
test_requests()
loop.run_until_complete(test_aiohttp())
anticens.disable()
# Pixiv is blocked in China
test_requests()
loop.run_until_complete(test_aiohttp())
if __name__ == '__main__':
main()