0
# Deprecated API
1
2
Legacy functionality maintained for backward compatibility. These APIs are deprecated and users should migrate to newer alternatives or use python-socks directly.
3
4
## Capabilities
5
6
### Deprecated Utility Functions
7
8
Legacy connection functions that provide direct proxy socket connections. These are deprecated in favor of using python-socks directly.
9
10
```python { .api }
11
async def open_connection(
12
proxy_url=None,
13
host=None,
14
port=None,
15
*,
16
proxy_type=ProxyType.SOCKS5,
17
proxy_host='127.0.0.1',
18
proxy_port=1080,
19
username=None,
20
password=None,
21
rdns=True,
22
loop=None,
23
**kwargs
24
):
25
"""
26
DEPRECATED: Open connection through proxy.
27
28
Use https://github.com/romis2012/python-socks directly instead.
29
30
Args:
31
proxy_url (str, optional): Proxy URL string
32
host (str): Target hostname (required)
33
port (int): Target port (required)
34
proxy_type (ProxyType): Type of proxy (default: SOCKS5)
35
proxy_host (str): Proxy hostname (default: '127.0.0.1')
36
proxy_port (int): Proxy port (default: 1080)
37
username (str, optional): Proxy username
38
password (str, optional): Proxy password
39
rdns (bool): Remote DNS resolution (default: True)
40
loop: Event loop (optional)
41
**kwargs: Additional arguments passed to asyncio.open_connection
42
43
Returns:
44
Tuple[StreamReader, StreamWriter]: Connected stream objects
45
46
Raises:
47
ValueError: If host or port not specified
48
DeprecationWarning: Always emitted when called
49
"""
50
51
async def create_connection(
52
proxy_url=None,
53
protocol_factory=None,
54
host=None,
55
port=None,
56
*,
57
proxy_type=ProxyType.SOCKS5,
58
proxy_host='127.0.0.1',
59
proxy_port=1080,
60
username=None,
61
password=None,
62
rdns=True,
63
loop=None,
64
**kwargs
65
):
66
"""
67
DEPRECATED: Create connection through proxy.
68
69
Use https://github.com/romis2012/python-socks directly instead.
70
71
Args:
72
proxy_url (str, optional): Proxy URL string
73
protocol_factory: Protocol factory function (required)
74
host (str): Target hostname (required)
75
port (int): Target port (required)
76
proxy_type (ProxyType): Type of proxy (default: SOCKS5)
77
proxy_host (str): Proxy hostname (default: '127.0.0.1')
78
proxy_port (int): Proxy port (default: 1080)
79
username (str, optional): Proxy username
80
password (str, optional): Proxy password
81
rdns (bool): Remote DNS resolution (default: True)
82
loop: Event loop (optional)
83
**kwargs: Additional arguments passed to loop.create_connection
84
85
Returns:
86
Tuple[Transport, Protocol]: Connected transport and protocol
87
88
Raises:
89
ValueError: If protocol_factory, host, or port not specified
90
DeprecationWarning: Always emitted when called
91
"""
92
```
93
94
### Deprecated Connector Classes
95
96
Legacy connector classes and constants maintained for backward compatibility.
97
98
```python { .api }
99
class SocksVer:
100
"""
101
DEPRECATED: Legacy SOCKS version constants.
102
103
Use ProxyType enum instead.
104
"""
105
SOCKS4 = 1
106
SOCKS5 = 2
107
108
class SocksConnector(ProxyConnector):
109
"""
110
DEPRECATED: Legacy SOCKS connector.
111
112
Use ProxyConnector instead.
113
114
Inherits all functionality from ProxyConnector but emits
115
deprecation warnings when used.
116
"""
117
def __init__(self, socks_ver=SocksVer.SOCKS5, **kwargs):
118
"""
119
Create legacy SOCKS connector.
120
121
Args:
122
socks_ver (int): SOCKS version using SocksVer constants
123
**kwargs: Arguments passed to ProxyConnector
124
125
Emits:
126
DeprecationWarning: Always emitted when instantiated
127
"""
128
129
@classmethod
130
def from_url(cls, url, **kwargs):
131
"""
132
Create legacy SOCKS connector from URL.
133
134
Args:
135
url (str): Proxy URL
136
**kwargs: Arguments passed to ProxyConnector
137
138
Returns:
139
SocksConnector: Legacy connector instance
140
141
Emits:
142
DeprecationWarning: Always emitted when called
143
"""
144
```
145
146
### Deprecated Exception Aliases
147
148
Legacy exception names that alias to the current python-socks exceptions.
149
150
```python { .api }
151
SocksError = ProxyError
152
"""DEPRECATED: Alias for ProxyError. Use ProxyError instead."""
153
154
SocksConnectionError = ProxyConnectionError
155
"""DEPRECATED: Alias for ProxyConnectionError. Use ProxyConnectionError instead."""
156
```
157
158
### Migration Guidelines
159
160
#### From SocksConnector to ProxyConnector
161
162
```python
163
# Old deprecated way
164
from aiohttp_socks import SocksConnector, SocksVer
165
166
connector = SocksConnector(
167
socks_ver=SocksVer.SOCKS5,
168
host='127.0.0.1',
169
port=1080
170
)
171
172
# New recommended way
173
from aiohttp_socks import ProxyConnector, ProxyType
174
175
connector = ProxyConnector(
176
proxy_type=ProxyType.SOCKS5,
177
host='127.0.0.1',
178
port=1080
179
)
180
```
181
182
#### From Utility Functions to python-socks
183
184
```python
185
# Old deprecated way
186
from aiohttp_socks import open_connection
187
188
reader, writer = await open_connection(
189
host='example.com',
190
port=80,
191
proxy_host='127.0.0.1',
192
proxy_port=1080
193
)
194
195
# New recommended way
196
from python_socks.async_.asyncio import Proxy
197
198
proxy = Proxy.from_url('socks5://127.0.0.1:1080')
199
stream = await proxy.connect('example.com', 80)
200
reader, writer = stream.reader, stream.writer
201
```
202
203
#### From Legacy Exceptions
204
205
```python
206
# Old deprecated way
207
from aiohttp_socks import SocksError, SocksConnectionError
208
209
try:
210
# proxy operations
211
pass
212
except SocksConnectionError as e:
213
print(f"Connection failed: {e}")
214
except SocksError as e:
215
print(f"Proxy error: {e}")
216
217
# New recommended way
218
from aiohttp_socks import ProxyError, ProxyConnectionError
219
220
try:
221
# proxy operations
222
pass
223
except ProxyConnectionError as e:
224
print(f"Connection failed: {e}")
225
except ProxyError as e:
226
print(f"Proxy error: {e}")
227
```