简体   繁体   English

不断收到这个 AttributeError:部分初始化的模块 'schedule' 没有属性 'every'

[英]Keep getting this AttributeError: partially initialized module 'schedule' has no attribute 'every'

Is anyone able to help me with this error I'm making a with a Coronavirus tracker twitter bot with python.有人能帮我解决这个错误吗? It basically scrapes data from https://www.worldometers.info/coronavirus/ and post updates on twitter.它基本上从https://www.worldometers.info/coronavirus/中抓取数据,并在 twitter 上发布更新。

The problem I'm having is to do with the scheduler on line 5 & 24.我遇到的问题与第 5 行和第 24 行的调度程序有关。

Traceback (most recent call last):回溯(最近一次通话最后):

File "C:\Users\Abdul\Documents\CoronavirusBot\twitter_bot.py", line 5, in文件“C:\Users\Abdul\Documents\CoronavirusBot\twitter_bot.py”,第 5 行,在

import schedule进口时间表

File "C:\Users\Abdul\Documents\CoronavirusBot\schedule.py", line 24, in文件“C:\Users\Abdul\Documents\CoronavirusBot\schedule.py”,第 24 行,在

schedule.every().day.at("19:51").do(submit_tweet) schedule.every().day.at("19:51").do(submit_tweet)

AttributeError: partially initialized module 'schedule' has no attribute 'every' (most likely due to a circular import) AttributeError:部分初始化的模块 'schedule' 没有属性 'every'(很可能是由于循环导入)

Twitter_bot.py Twitter_bot.py

from config import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
import tweepy
import requests
import schedule
import time
from lxml import html


def create_tweet():
    response = requests.get('https://www.worldometers.info/coronavirus/')
    doc = html.fromstring(response.content)
    total, deaths, recovered = doc.xpath('//div[@class="maincounter-number"]/span/text()')

    tweet = f'''Coronavirus Latest Updates
Total cases: {total}
Recovered: {recovered}
Deaths: {deaths}

Source: https://www.worldometers.info/coronavirus/

#coronavirus #covid19 #coronavirusnews #coronavirusupdates
'''
    return tweet


if __name__ == '__main__':
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

    # Create API object
    api = tweepy.API(auth)

    try:
        api.verify_credentials()
        print('Authentication Successful')
    except:
        print('Error while authenticating API')
        sys.exit(1)
    while True:
        schedule.run_pending()
        time.sleep(1)

    tweet = create_tweet()
    api.update_status(tweet)
    print('Tweet successful')
else:
   print('error') ``` 

 


 **Schedule.py**
```import schedule

#define function create tweet

#auth and create tweet
def submit_tweet(*args, **kwargs): #Add the needed args here
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

    # Create API object
    api = tweepy.API(auth)

    try:
        api.verify_credentials()
        print('Authentication Successful')
    except:
        print('Error while authenticating API')
        sys.exit(1)

    tweet = create_tweet()
    api.update_status(tweet)
    print('Tweet successful')

schedule.every().day.at("21:19").do(submit_tweet)

while True:
    schedule.run_pending()
    time.sleep(1)

This happens your python code file name is 'schedule.py'.这发生在您的 python 代码文件名是“schedule.py”。 If you change the file name to another one, you will no longer see the error.如果您将文件名更改为另一个,您将不再看到该错误。

you should not use schedule(shcedule.py) for your file name你不应该使用 schedule(shcedule.py) 作为你的文件名

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:部分初始化的模块“pandas”没有属性“DataFrame” - AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame' Python/Json AttributeError:部分初始化的模块“json”没有属性 - Python/Json AttributeError: partially initialized module 'json' has no attribute attributererror: 部分初始化的模块“turtle”没有属性“bgcolor” - attributeerror: partially initialized module 'turtle' has no attribute 'bgcolor' AttributeError: 部分初始化的模块“juego”没有属性“VENTANA_VERTICAL”(很可能是由于循环导入) - AttributeError: partially initialized module 'juego' has no attribute 'VENTANA_VERTICAL' (most likely due to a circular import) AttributeError: 部分初始化的模块“sympy”没有属性“S”(很可能是由于循环导入) - AttributeError: partially initialized module 'sympy' has no attribute 'S' (most likely due to a circular import) AttributeError: 部分初始化的模块“folium”没有属性“Map”(很可能是由于循环导入) - AttributeError: partially initialized module 'folium' has no attribute 'Map' (most likely due to a circular import) AttributeError:部分初始化的模块'pims'没有属性'pyav_reader'很可能是由于循环导入) - AttributeError: partially initialized module 'pims' has no attribute 'pyav_reader' most likely due to a circular import) AttributeError:部分初始化的模块“first_window”没有属性“InitialWindow”(很可能是由于循环导入) - AttributeError: partially initialized module 'first_window' has no attribute 'InitialWindow' (most likely due to a circular import) AttributeError:部分初始化的模块“turtle”没有属性“Pen”(很可能是由于循环导入) - AttributeError: partially initialized module 'turtle' has no attribute 'Pen' (most likely due to a circular import) AttributeError:部分初始化的模块“urllib.request”没有属性“urlopen”(很可能是由于循环导入) - AttributeError: partially initialized module 'urllib.request' has no attribute ' urlopen' (most likely due to a circular import)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM