Proxy-Session 是一个 python 模块,有助于向 HTTP 服务器发出可靠的代理请求。该模块的当前版本是 0.1.1
项目描述
代理会话
Proxy-Session是一个 python 模块,有助于向 HTTP 服务器发出可靠的代理请求。
版本
当前版本是0.1.1.
安装
使用 git
git clone https://github.com/antaripchatterjee/Proxy-Session
cd Proxy-Session
python setup.py install
使用点子
pip install Proxy-Session
卸载
pip uninstall proxy_session
平台支持
这是一个跨平台的python模块,前提是python解释器的版本应该是3.6+。
API 参考
import requests
...
...
class ProxySession(requests.Session):
def __init__(self, user_=None, pass_=None, socks=False):
'''
@param user_: str[None] -> Username for proxy authentication
@param pass_: str[None] -> Password for proxy authentication
@param socks: bool[False] -> If True, it will perform a socks5
authentication, given the user_ and pass_ has been
provided. If False, it will perform a basic authent-
ication will be performed, provided the value of
user_ and pass_.
'''
super(ProxySession, self).__init__()
...
...
...
...
def make_request(self, url, method='GET', timeout=ProxySessionTimeout.SHORT_TIMEOUT, log = True, max_attempt = 100, **kwargv):
'''
@param url: str -> The target URL
@param method: str[GET] -> The HTTP method to be called
@param timeout: int[5] -> The timeout value, for the proxy request
@param log: bool[True] -> It will log the necessary information
@param max_attempt: int[100] -> Maximum number of attempt to reach the target URL,
must be a positve integer
@param **kwargv -> Other keyword arguments, which will be passed to requests.request
method
@return -> It will always return the tuple of two element, response and proxy_url
On success, it will return the reponse object, returned by the method call and
the proxy url. If the random proxy selection is made, it will return the proxy
url as a string, otherwise it will be same as keyword argument "proxies".
On Failure after maximum attempts, it will return a Response object, having
status_code -1 with empty content. The proxy url will be null in this case.
'''
...
...
...
...
从GitHub找到完整的源代码。
如果您需要使用socks代理发出请求,请确保安装PySocks。或者,只需运行以下命令。
pip install requests[socks]
如果您将关键字参数传递proxies给ProxySession.make_request方法(如requests.request(...)),它将阻止任何随机代理选择。
随机代理从Free Proxy List - Just Checked Proxy List中报废。此模块提供了一种可靠的方式来查找免费且实时的代理服务器,但是,它不会评估代理服务器的任何安全性,因此它不能保证您的个人和/或机密数据。使用付费代理总是比免费代理更好。
用法
from sys import stderr
from proxy_session import ProxySession
from proxy_session import ProxySessionTimeout
if __name__ == '__main__':
with ProxySession() as ps:
error_ = ps.error
if error_:
print('Error Status: ', error_[0], file=stderr)
print('Error:\n' + error_[1], file=stderr)
response, proxy_addr = ps.make_request('https://httpbin.org/ip', timeout=ProxySessionTimeout.LONG_TIMEOUT, log=True)
if response.status_code == 200:
print(f'Response Content:\n{response.text}')
print(f'Proxy URL: {proxy_addr}')
else:
print(f'{response}')
上面的代码在我测试时生成了以下输出。
Trying random free proxy[https]: http://103.109.58.102:46523
Trying random free proxy[https]: http://157.230.103.189:36366
Trying random free proxy[https]: http://85.15.152.39:3128
Response Content:
{
"origin": "85.15.152.39"
}
Proxy URL: http://85.15.152.39:3128
执照
Python 模块Proxy-Session带有MIT License。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
Proxy-Session-0.1.1.tar.gz
(6.4 kB
查看哈希)
内置分布
Proxy_Session-0.1.1-py3-none-any.whl
(6.9 kB
查看哈希)
关
Proxy_Session -0.1.1-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 1a7892b89e059494c2a5c88b58c055c0f9f48f3e3396ebd823842d28f4843944 |
|
| MD5 | 956f8eb8084c49b1af5cce4bd1def5f8 |
|
| 布莱克2-256 | 717ec4fe6c9c0de6ec1e3e19b2fdc68ece773112c475efe91da0dff1d3d452c7 |