Запрос:
{"ExternalId": "0e47c020cde85f604a18149ae3d33eb9538a60224785939df4ea69ee5dead0b3", "Name": "\u0411\u0430\u043d", "Query": "\u0411\u0430\u043d", "StartDate": "2019-10-27T14:28:53", "Type": 1, "Parameters": "{\"key\":\"source_type\", \"value\":\"32\"}"}
Ответ:
{"Request":"ExternalId=0e47c020cde85f604a18149ae3d33eb9538a60224785939df4ea69ee5dead0b3&Name=%D0%91%D0%B0%D0%BD&Query=%D0%91%D0%B0%D0%BD&StartDate=2019-10-27T14%3A28%3A53&Type=1&Parameters=%5B%7B%22key%22%3A%22sourcetype%22%2C+%22value%22%3A%2232%22%7D%5D","Errors":[{"Code":"Error/api/v0.9/report","Message":"Unexpected character encountered while parsing value: E. Path '', line 0, position 0."}]}
Токен:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjQ4MjcsInVzZXJOYW1lIjoiNTMyNDU5NjE0XzIzYWFjNzg0QG91dGVyLm1pbmRzY2FuLnJ1Iiwicm9sZXMiOlsiQW5hbHlzdCJdLCJleHAiOjE2MDM3MjI1MTQsInNhbHQiOiI1MzlhNjAyNmM1ZWU0NTYyODA0NTJkODZiNTdjNjM0YyJ9.5OaHYw9dDZXPfVdpS1hytPGNEIrpxOz614Smeqjpn8Y
2019-10-27T14:28:42.38081+00:00 app[bot.1]: 2019-10-27 14:28:42,380 (util.py:65 WorkerThread1) ERROR - TeleBot: "ApiException occurred, args=('A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:\n[b\'{"ok":false,"error_code":400,"description":"Bad Request: can\\\'t parse entities: Can\\\'t find end of the entity starting at byte offset 750"}\']',)
2019-10-27T14:28:42.380846+00:00 app[bot.1]: Traceback (most recent call last):
2019-10-27T14:28:42.380853+00:00 app[bot.1]: File "/app/.heroku/python/lib/python3.6/site-packages/telebot/util.py", line 59, in run
2019-10-27T14:28:42.380859+00:00 app[bot.1]: task(*args, **kwargs)
2019-10-27T14:28:42.380861+00:00 app[bot.1]: File "bot.py", line 71, in callback_inline
2019-10-27T14:28:42.380866+00:00 app[bot.1]: bot.send_message(call.message.chat.id, debugText, parse_mode='Markdown')
2019-10-27T14:28:42.380872+00:00 app[bot.1]: File "/app/.heroku/python/lib/python3.6/site-packages/telebot/__init__.py", line 598, in send_message
2019-10-27T14:28:42.380879+00:00 app[bot.1]: reply_markup, parse_mode, disable_notification))
2019-10-27T14:28:42.380881+00:00 app[bot.1]: File "/app/.heroku/python/lib/python3.6/site-packages/telebot/apihelper.py", line 140, in send_message
2019-10-27T14:28:42.380882+00:00 app[bot.1]: return _make_request(token, method_url, params=payload, method='post')
2019-10-27T14:28:42.380883+00:00 app[bot.1]: File "/app/.heroku/python/lib/python3.6/site-packages/telebot/apihelper.py", line 56, in _make_request
2019-10-27T14:28:42.380884+00:00 app[bot.1]: return _check_result(method_name, result)['result']
2019-10-27T14:28:42.380885+00:00 app[bot.1]: File "/app/.heroku/python/lib/python3.6/site-packages/telebot/apihelper.py", line 75, in _check_result
2019-10-27T14:28:42.380886+00:00 app[bot.1]: raise ApiException(msg, method_name, result)
2019-10-27T14:28:42.380893+00:00 app[bot.1]: telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
2019-10-27T14:28:42.380901+00:00 app[bot.1]: [b'{"ok":false,"error_code":400,"description":"Bad Request: can\'t parse entities: Can\'t find end of the entity starting at byte offset 750"}']
2019-10-27T14:28:42.380907+00:00 app[bot.1]: "
2019-10-27T14:28:42.381024+00:00 app[bot.1]: 2019-10-27 14:28:42,380 (__init__.py:417 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
2019-10-27T14:28:42.381026+00:00 app[bot.1]: [b'{"ok":false,"error_code":400,"description":"Bad Request: can\'t parse entities: Can\'t find end of the entity starting at byte offset 750"}']"
2019-10-27T14:29:13.06735+00:00 heroku[bot.1]: Stopping all processes with SIGTERM
2019-10-27T14:29:13.18364+00:00 heroku[bot.1]: Process exited with status 143
POST http://api.mindscan.ru:10088/test/data/api/v0.9/report
{
"ExternalId":" 290f9ebf-56ad-49ad-b83a-0244118b56c3",
"Name": "Дональд Трамп",
"Query": "Дональд* Трамп*",
"StartDate": "2019-08-05T23:51:32",
"Type": 1,
"Parameters": "[{"key":"source_type","value":"32"}]"
}
# -*- coding: utf-8 -*-
import config
import telebot
import requests
import secrets
import json
import re
from telebot import types
from datetime import datetime
bot = telebot.TeleBot(config.token_bot)
@bot.message_handler(commands=['start'])
def get_document_query(message):
# CREATE REQUES
body = {"UserId": message.from_user.id, "UserName": message.from_user.username, "UserFirstName": message.from_user.first_name, "UserLastName": message.from_user.last_name, "ProjectKey": config.project_key}
us_r = requests.post('https://mindscan.ru/Outer/GetToken', data=body)
text = 'Введите поисковый запрос'
data = json.loads(us_r.text)
token = data.get('Jwt')
data = {'token': token}
with open('dataUserTG.json', 'w', encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
# SEND MESSAGE
msg = bot.send_message(message.chat.id, text)
# CREATE NEXT STEP
bot.register_next_step_handler(msg, query_confirm)
@bot.message_handler(regexp='подтвердить отчёт')
def query_confirm(message):
# CREATE TEXT
text = 'Ваш поисковый запрос: *' + message.text + '*'
keyboard = types.InlineKeyboardMarkup()
callback_button = types.InlineKeyboardButton(text="Подтвердить", callback_data="confirm")
keyboard.add(callback_button)
# SEND MESSAGE
bot.send_message(message.chat.id, text, parse_mode='Markdown', reply_markup=keyboard)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == "confirm":
# HEADERS
token = ''
with open('dataUserTG.json', 'r') as json_data:
d = json.load(json_data)
token = d.get('token')
headers = {'Authorization': token}
# PARAMS
text = call.message.text.replace('Ваш поисковый запрос: ', '') # TEXT
query = re.sub(r'\b(\w{4,})\b', r'\1*', text) # QUERY TEXT
guid = secrets.token_hex(32) # UNIQUE CODE
data = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') # TIMESTAMP
typeDoc = 1 # TYPE
# TYPE
params = '[{"key":"source_type", "value":"32"}]'
# GET REQUEST
body = {"ExternalId": guid, "Name": text, "Query": query, "StartDate": data, "Type": typeDoc, "Parameters": params}
get_doc = requests.post('http://api.mindscan.ru:10088/test/data/api/v0.9/report', data=body, headers=headers)
# RESPONSE
debugText = "*Запрос:*\n" + json.dumps(body) + "\n*Ответ:*\n" + get_doc.text + "\n*Токен:*\n" + token
# SEND MESSAGE
bot.send_message(call.message.chat.id, debugText, parse_mode='Markdown')
if __name__ == '__main__':
bot.polling(none_stop=True)