K
K
Kirillkin2021-08-28 11:37:22
Python
Kirillkin, 2021-08-28 11:37:22

Can't see attribute, module 'const' has no attribute 'MY_ID'?

I am writing a weather bot, there is a check by id, MI_ID has a value in the const file, but an error pops up in the code that there is no MY_ID attribute in this module, although it seems to be there, what could it be?

import requests
import json
import time
import const
from pprint import pprint

def main():

    while True:
        url = const.URL.format(token=const.TOKEN, method=const.UPDATE_METH)
        
        content = requests.get(url).text

        data = json.loads(content)
        result = data['result'][::-1]
        needed_part = None

        for elem in result:
           if elem['message']['chat']['id'] == const.MY_ID:
                needed_part = elem
                break

        if const.UPDATE_ID != needed_part['update_id']:
               pass

        if not const.UPDATE_ID:
           with open ('update_id', 'W') as file:
               file.write(str(needed_part['update_id']))
        
            
        pprint(needed_part)
           
       
        #pprint(data)
        break

        time.sleep(2)



if __name__=='__main__':
    main()


const file

TOKEN = 'token'

URL = 'https://api.telegram.org/bot{token}/{method}'

UPDATE_METH = 'getUpdates'

SEND_METH = 'sendMessage'

MY_ID = 564411943

UPDATE_ID_FILE_PATH ='update_id'

with open('update_id') as file:
    UPDATE_ID = file.readline()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirillkin, 2021-08-28
@9BiNbom9

It looks like the Const file was not updated, the error was updated, but a new one appeared, in the 4th line of the code, import const, "An exception was thrown - invalid syntax (const.py, line 11)" already points to the line in the const file, which contains MY_ID value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question