为什么我的python instagram发布机器人会出现这个错误?
我想制作一个机器人,从pics文件夹上传一张随机图片。这在预定的时间内发生(出于测试原因,我将其设置为0.2分钟)。机器人应该上传一个名为pic.jpg的文件,然后删除该文件并将一个随机文件重命名为pic.jpg为什么我的python instagram发布机器人会出现这个错误?,python,bots,instagram,Python,Bots,Instagram,我想制作一个机器人,从pics文件夹上传一张随机图片。这在预定的时间内发生(出于测试原因,我将其设置为0.2分钟)。机器人应该上传一个名为pic.jpg的文件,然后删除该文件并将一个随机文件重命名为pic.jpg from instabot import Bot import schedule import time import os import random bot = Bot() bot.login(username = "XXX",password = &
from instabot import Bot
import schedule
import time
import os
import random
bot = Bot()
bot.login(username = "XXX",password = "XXX")
def upload():
bot.upload_photo("pics/pic.jpg",caption =" ")
delren()
path = r"pics/"
old_file_name = random.choice([
x for x in os.listdir(path)
if os.path.isfile(os.path.join(path, x))
])
new_file_name = os.path.join("pics/", "pic.jpg")
def delren():
if os.path.exists("pics/pic.jpg"):
os.remove("pics/pic.jpg")
else:
os.rename("pics/"+old_file_name, new_file_name)
os.rename("pics/"+old_file_name, new_file_name)
#schedule.every(8).hours.do(upload)
schedule.every(0.2).minutes.do(upload)
while True:
schedule.run_pending()
time.sleep(1)
回溯(最近一次呼叫最后一次):
文件“insta.py”,第34行,在
schedule.run_pending()
文件“/usr/local/lib/python3.8/dist-packages/schedule/_-init__uu.py”,第563行,运行中
默认\u计划程序。运行\u挂起()
文件“/usr/local/lib/python3.8/dist-packages/schedule/_-init__uu.py”,第94行,运行中
自我运行作业(作业)
文件“/usr/local/lib/python3.8/dist-packages/schedule/_-init___.py”,第147行,在运行作业中
ret=job.run()
文件“/usr/local/lib/python3.8/dist-packages/schedule/_-init__.py”,第466行,正在运行
ret=self.job_func()
上传文件“insta.py”,第13行
德伦()
文件“insta.py”,第27行,在delren中
重命名(“pics/”+旧文件名,新文件名)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“pics/brunette_rage_mad.jpg”->“pics/pic.jpg”
2020-12-14 22:26:13298-信息-请求总数:41
您尝试重命名文件两次。第二次它将不在那里
def delren():
if os.path.exists("pics/pic.jpg"):
os.remove("pics/pic.jpg")
else:
# If pic.jpg doesn't exist then pics/<old_file_name> is moved to pics/pic.jpg
os.rename("pics/"+old_file_name, new_file_name)
# If you just renamed pics/<old_file_name> in the last line then it won't exist. Hence the error.
os.rename("pics/"+old_file_name, new_file_name)
def delren():
如果os.path.存在(“pics/pic.jpg”):
删除操作系统(“pics/pic.jpg”)
其他:
#如果pic.jpg不存在,则pics/将移动到pics/pic.jpg
重命名(“pics/”+旧文件名,新文件名)
#如果在最后一行中重命名pics/则它将不存在。因此出现了错误。
重命名(“pics/”+旧文件名,新文件名)
你能不能编辑你的帖子,放一些东西来覆盖你的用户名和密码,并在有人看到的情况下进行更改?@TimothyChen哦,是的,很好,忘了这一点。谢谢
def delren():
if os.path.exists("pics/pic.jpg"):
os.remove("pics/pic.jpg")
else:
# If pic.jpg doesn't exist then pics/<old_file_name> is moved to pics/pic.jpg
os.rename("pics/"+old_file_name, new_file_name)
# If you just renamed pics/<old_file_name> in the last line then it won't exist. Hence the error.
os.rename("pics/"+old_file_name, new_file_name)