Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d52958c

Browse filesBrowse files
author
Boris
committed
修复代理池问题
1 parent 29cb39e commit d52958c
Copy full SHA for d52958c

3 files changed

+46-20Lines changed: 46 additions & 20 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎feapder/VERSION‎

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.4.2
Collapse file

‎feapder/network/proxy_pool.py‎

Copy file name to clipboardExpand all lines: feapder/network/proxy_pool.py
+6-19Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import requests
1515

1616
from feapder import setting
17-
from feapder.utils import log
1817
from feapder.utils import tools
18+
from feapder.utils.log import log
1919

2020
# 建立本地缓存代理文件夹
2121
proxy_path = os.path.join(os.path.dirname(__file__), "proxy_file")
@@ -174,7 +174,7 @@ def check_proxy(
174174
type=0,
175175
timeout=5,
176176
logger=None,
177-
show_error_log=False,
177+
show_error_log=True,
178178
**kwargs,
179179
):
180180
"""
@@ -187,7 +187,7 @@ def check_proxy(
187187
:return:
188188
"""
189189
if not logger:
190-
logger = log.get_logger(__file__)
190+
logger = log
191191
ok = 0
192192
if type == 0 and ip and port:
193193
# socket检测成功 不代表代理一定可用 Connection closed by foreign host. 这种情况就不行
@@ -207,21 +207,9 @@ def check_proxy(
207207
"http": "http://{}:{}".format(ip, port),
208208
"https": "https://{}:{}".format(ip, port),
209209
}
210-
target_url = random.choice(
211-
[
212-
"http://www.baidu.com",
213-
# "http://httpbin.org/ip",
214-
]
215-
)
216210
try:
217211
r = requests.get(
218-
target_url,
219-
headers={
220-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36"
221-
},
222-
proxies=proxies,
223-
timeout=timeout,
224-
stream=True,
212+
"http://www.baidu.com", proxies=proxies, timeout=timeout, stream=True
225213
)
226214
ok = 1
227215
r.close()
@@ -247,7 +235,6 @@ def __init__(
247235
max_proxy_use_num=10000,
248236
delay=30,
249237
use_interval=None,
250-
logger=None,
251238
**kwargs,
252239
):
253240
"""
@@ -294,7 +281,7 @@ def __init__(
294281
self.proxy_id = self.proxy_ip_port
295282

296283
# 日志处理器
297-
self.logger = logger or log.get_logger(__file__)
284+
self.logger = log
298285

299286
def get_proxies(self):
300287
self.use_num += 1
@@ -418,7 +405,7 @@ def __init__(self, **kwargs):
418405
self.proxy_source_url = list(set(self.proxy_source_url))
419406
kwargs.update({"proxy_source_url": self.proxy_source_url})
420407
# 处理日志
421-
self.logger = kwargs.get("logger") or log.get_logger(__file__)
408+
self.logger = kwargs.get("logger") or log
422409
kwargs["logger"] = self.logger
423410
if not self.proxy_source_url:
424411
self.logger.warn("need set proxy_source_url or proxy_instance")
Collapse file

‎tests/test_proxies_pool.py‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on 2021/4/3 4:25 下午
4+
---------
5+
@summary:
6+
---------
7+
@author: Boris
8+
@email: boris_liu@foxmail.com
9+
"""
10+
from feapder.network.proxy_pool import ProxyPool, check_proxy
11+
import requests
12+
13+
url = "http://tunnel-api.apeyun.com/h?id=2020120800184471713&secret=3U1fEJPuabi3y2QJ&limit=10&format=txt&auth_mode=auto"
14+
15+
proxy_pool = ProxyPool(size=-1, proxy_source_url=url)
16+
17+
print(proxy_pool.get())
18+
#
19+
# headers = {
20+
# "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
21+
# "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
22+
# "Accept-Encoding": "gzip, deflate, br",
23+
# "Accept-Language": "zh-CN,zh;q=0.9",
24+
# "Connection": "keep-alive",
25+
# }
26+
#
27+
#
28+
# resp = requests.get(
29+
# "http://www.baidu.com",
30+
# headers=headers,
31+
# proxies={
32+
# "https": "https://182.106.136.67:13586",
33+
# "http": "http://182.106.136.67:13586",
34+
# },
35+
# )
36+
# print(resp.text)
37+
#
38+
# a = check_proxy("182.106.136.67", "13586", show_error_log=True, type=1)
39+
# print(a)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.