Skip to content

Commit 07a7953

Browse files
committed
readme
1 parent 12f1c1e commit 07a7953

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

README.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ Yes, you can download virtualbox image [here](https://drive.google.com/file/d/1z
3535

3636
## How to get proxies?
3737

38-
proxy_py has server based on aiohttp which is listening 127.0.0.1:55555(you can change it in settings file) and provides proxies. To get proxies you should send following json request:
38+
proxy_py has server based on aiohttp which is listening 127.0.0.1:55555
39+
(you can change it in settings file) and provides proxies.
40+
To get proxies you should send following json request:
3941

4042
```json
4143
{
@@ -46,41 +48,47 @@ proxy_py has server based on aiohttp which is listening 127.0.0.1:55555(you can
4648
```
4749

4850
Note: order_by makes result sorting by one or more fields separated by comma.
49-
You can skip it. The required fields are model and method.
51+
You can skip it. The required fields are `model` and `method`.
5052

5153
It will return json response like this:
5254

5355
```json
5456
{
55-
"status": "ok",
5657
"count": 1,
57-
"has_more": true,
5858
"data": [{
5959
"address": "http://127.0.0.1:8080",
60-
"auth_data": null,
60+
"auth_data": "",
6161
"bad_proxy": false,
6262
"domain": "127.0.0.1",
6363
"last_check_time": 1509466165,
6464
"number_of_bad_checks": 0,
6565
"port": 8080,
6666
"protocol": "http",
67-
"uptime": 1509460949,
67+
"response_time": 461691,
68+
"uptime": 1509460949
6869
}
69-
]
70+
],
71+
"has_more": false,
72+
"status": "ok",
73+
"status_code": 200
7074
}
7175
```
7276

73-
Note: All fields except *protocol*, *domain*, *port*, *auth_data*, *checking_period* and *address* can be null
77+
Note: All fields except *protocol*, *domain*, *port*, *auth_data*,
78+
*checking_period* and *address* can be null
7479

7580
Or error if something went wrong:
7681

7782
```json
7883
{
79-
"status": "error",
80-
"error_message": "You should specify model",
84+
"error_message": "You should specify \"model\"",
85+
"status": "error",
86+
"status_code": 400
8187
}
8288
```
8389

90+
Note: status_code is also duplicated in HTTP status code
91+
8492
Example using curl:
8593

8694
`curl -X POST http://example.com:55555 -H "Content-Type: application/json" --data '{"model": "proxy", "method": "get"}'`
@@ -102,11 +110,15 @@ def get_proxies():
102110
"model": "proxy",
103111
"method": "get",
104112
}
105-
106-
response = json.loads(requests.post('http://example.com:55555', json=json_data).text)
107-
if response['status'] == 'ok':
113+
114+
response = requests.post('http://example.com:55555', json=json_data)
115+
if response.status_code == 200:
116+
response = json.loads(response.text)
108117
for proxy in response['data']:
109118
result.append(proxy['address'])
119+
else:
120+
# check error here
121+
pass
110122

111123
return result
112124
```
@@ -125,9 +137,13 @@ async def get_proxies():
125137

126138
with aiohttp.ClientSession() as session:
127139
with session.post('http://example.com:55555', json=json_data) as response:
128-
response = json.loads(await response.text())
129-
for proxy in response['data']:
130-
result.append(proxy['address'])
140+
if response.status == 200:
141+
response = json.loads(await response.text())
142+
for proxy in response['data']:
143+
result.append(proxy['address'])
144+
else:
145+
# check error here
146+
pass
131147

132148
return result
133149
```
@@ -138,7 +154,8 @@ Read more about API [here](https://github.com/DevAlone/proxy_py/tree/master/doc
138154

139155
## How to test it?
140156

141-
If you made changes to code and want to check that you didn't break anything, go [here](https://github.com/DevAlone/proxy_py/tree/master/docs/tests.md)
157+
If you made changes to code and want to check that you didn't break
158+
anything, go [here](https://github.com/DevAlone/proxy_py/tree/master/docs/tests.md)
142159

143160
## How to deploy on production using supervisor, nginx and postgresql in 8 steps?
144161

0 commit comments

Comments
 (0)