Answer the question
In order to leave comments, you need to log in
How to make friends Python and Callback API?
I can't figure out what I'm doing wrong.
I connected my vps to VK, where jsons are now constantly coming, because I can't answer correctly.
Here is what is written in the documentation :
Обратите внимание: после получения уведомления Ваш сервер должен возвращать строку "ok"
и статус HTTP 200. Если сервер несколько раз подряд вернет ошибку, Callback API временно
перестанет отправлять на него уведомления.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import logging
from time import sleep
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
sock.bind(('0.0.0.0', 80))
except Exception:
logging.exception('processing request')
sock.listen(1)
#conn, addr = sock.accept()
#print('connected:'+str(addr))
ans = b"2fc3154"
status = b"HTTP/1.1 200 ok"
while True:
conn, addr = sock.accept()
print('connected:'+str(addr))
print(conn)
#conn.settimeout(5)
data = conn.recv(512)
if not data:
break
print(data)
#conn.send(b'ok\n')
conn.send(bytes('HTTP/1.1 200 OK\nConnection: close\n\n', 'UTF-8'))
conn.send(b'ok')
#break
conn.close()
sock.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question