Python 继续获取此属性错误:部分初始化模块';附表';没有属性';每';
有人能帮我解决这个错误吗?我正在用带有python的冠状病毒跟踪程序twitter bot进行测试。它基本上是从twitter上抓取数据并发布更新 我遇到的问题与第5行和第24行的调度程序有关 回溯(最近一次呼叫最后一次): 文件“C:\Users\Abdul\Documents\CoronavirusBot\twitter\u bot.py”,第5行,在 进口时间表 文件“C:\Users\Abdul\Documents\CoronavirusBot\schedule.py”,第24行,在 计划。每()天。在(“19:51”).do(提交_tweet) AttributeError:部分初始化的模块“schedule”没有属性“every”(很可能是由于循环导入) Twitter\u bot.pyPython 继续获取此属性错误:部分初始化模块';附表';没有属性';每';,python,Python,有人能帮我解决这个错误吗?我正在用带有python的冠状病毒跟踪程序twitter bot进行测试。它基本上是从twitter上抓取数据并发布更新 我遇到的问题与第5行和第24行的调度程序有关 回溯(最近一次呼叫最后一次): 文件“C:\Users\Abdul\Documents\CoronavirusBot\twitter\u bot.py”,第5行,在 进口时间表 文件“C:\Users\Abdul\Documents\CoronavirusBot\schedule.py”,第24行,在 计
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)
您已将您的脚本命名为
schedule.py
-因此导入计划
看到的是,而不是预期的模块。尝试将其重命名为其他模块,但我仍然收到相同的错误可能是在同一文件夹中创建了schedule.pyc
或类似的文件,你还需要删除。设法修复了错误,这是伟大的,但它说的身份验证成功,但实际上没有推特。