-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_webhook.py
executable file
·44 lines (35 loc) · 1.04 KB
/
test_webhook.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
#!/usr/bin/env python3
import requests
import json
def test_post_request():
"""Test POST request to local server."""
url = 'http://127.0.0.1:8090/'
payload = {
'test_key': 'test_value',
'number': 123
}
try:
response = requests.post(
url,
data=json.dumps(payload),
headers={
'User-Agent': 'Test Webhook Logger',
'Content-Length': '16',
'Accept-Encoding': 'gzip'
}
)
print(f'Status Code: {response.status_code}')
print('\nResponse Headers:')
for key, value in response.headers.items():
print(f'{key}: {value}')
print('\nResponse Body:')
try:
print(json.dumps(response.json(), indent=2))
except:
print(response.text)
except requests.exceptions.ConnectionError:
print(f'Failed to connect to {url}')
except Exception as e:
print(f'Error: {str(e)}')
if __name__ == '__main__':
test_post_request()