Trying to make a mini bot for this lesson https://proglib.io/p/python-vk-api-3/ But on the server it gives out mistake

here is the code

# A very simple Flask Hello World app for you to get started with... import vk from time import sleep from lxml import html import requests as req from flask import Flask login = '89326949892' password = '12345qwerty' vk_id = '3570608' #ID_ВАШЕГО_ПРИЛОЖЕНИЯ session = vk.AuthSession(app_id=vk_id, user_login=login, user_password=password) vkapi = vk.API(session) messages = vkapi.messages.get(count=1) last = messages['items'][0]['id'] app = Flask(__name__) @app.route('/') def hello_world(): return 'Привет!' def bash(id, mode='u'): try: r = req.get('http://bash.im/random') doc = html.document_fromstring(r.text) bash = '\n'.join(doc.xpath('//*[@id="body"]/div[3]/div[@class="text"]/text()')) if mode == 'c': vkapi.messages.send(chat_id=id, message=bash) else: vkapi.messages.send(user_id=id, message=bash) except Exception as e: print(e) if "~bash~" in message['body']: if 'chat_id' in message: bash(message['chat_id'], 'c') else: bash(message['user_id']) def print_help(id, mode='u'): try: message = """=== VK-бот === Доступные команды: &#_9989; ~bash~ -- случайная цитата с bash.im &#_9989; ~help~ -- показать помощь""" if mode == 'c': vkapi.messages.send(chat_id=id, message=message) else: vkapi.messages.send(user_id=id, message=message) except Exception as e: print(e) if "~help~" in message['body']: if 'chat_id' in message: print_help(message['chat_id'], 'c') else: print_help(message['user_id']) while True: try: messages = vkapi.messages.get(last_message_id=last) except Exception as e: print(e) sleep(4) continue if not messages['items']: # Если нет новых сообщений sleep(4) continue last = messages['items'][0]['id'] for message in messages['items']: # временные заглушки if "~bash~" in message['body']: bash(message['user_id']) sleep(4) 
  • You are offered to look at the logs (* .error.log) there for sure the answer. - PavelD

1 answer 1

For some reason it seems to me that you have a problem with tabulation. In addition, vk is an old module, where it is better to use vk_api (imho it is updated, more convenient and it has more functions). And if suddenly it will not be enough for you to * .error.log, run your script in the console that is there, and see the error.

And as for your project as a whole, VC doesn’t like bots pages very much, but it is loyal to bots groups. If you can make it under the group using the CallBack API. Or under the page, but with LongPoll and run on your machine. On pythonanywhere give very little CPU time for this.